Here are the collections I'm working with
Fee package collection
{
"_id": ObjectId("591abc701c9dfa0a6e7608e6"),
"fee_package_name": "abc",
"fee_structure": [{
"fee_name": "Fee1",
"fee_amount": 1550
},
{
"fee_name": "Fee2",
"fee_amount": 1750
},
{
"fee_name": "Fee3",
"fee_amount": 550
}
],
"total_fee_amount": 3850.0,
}
Student fee collection
{
_id: ObjectId("585a98d7fc6c0468218267f9"),
applied_fee_packages: [
{
fee_package_id: ObjectId("591abc701c9dfa0a6e7608e6"),
applied_discount: 0
},
{
fee_package_id: ObjectId("591abc701c9dfa0a6e7608e7"),
applied_discount: 0
}
]
}
Laravel: Model: FeePackage:
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class FeePackage extends Eloquent
{
protected $collection = 'fee_packages';
public function studentFee() {
return $this->belongsTo('App\Models\StudentFee');
}
}
Laravel: Model: StudentFee:
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class StudentFee extends Eloquent
{
protected $collection = 'student_fees';
public function feePackages() {
return $this->hasMany('App\Models\FeePackage');
}
}
I have tried to define hasMany relationship i.e student fee hasMany fee packages and I'm trying to retrieve a student with all fee packages applied to him.
With these documents I get the first student fee like this:
$feeCollection = StudentFee::with('feePackages')->first();
output:
{
_id: "585a98d7fc6c0468218267f9",
fee_packages: []
}
I only get the response without the fee package details for a given student fee id.
Appreciate any pointers to resolve this.
Thanks in advance