in this below result of fetch data:
{
"purchases": [
{
"id": 1,
"member_id": 1,
"mediator_id": 2,
"type": null,
"cash": 38712402,
"created_at": "2017-11-08 06:40:45",
"updated_at": "2017-11-08 06:40:45",
"deleted_at": null,
"cheques": [
{
"id": 1,
"purchase_id": 1,
"expire_date": "1396-01-19",
"amount": 97094060,
"isRejected": 0,
"created_at": "2017-11-08 06:40:45",
"updated_at": "2017-11-08 06:40:45",
"deleted_at": null
}
]
},
{
"id": 2,
"member_id": 1,
"mediator_id": 2,
"type": null,
"cash": 46760191,
"created_at": "2017-11-08 06:40:45",
"updated_at": "2017-11-08 06:40:45",
"deleted_at": null,
"cheques": []
}
]
}
which i get that by this code:
$purchases = \App\Purchase::with('cheques')->where('member_id',
$request->userId)->get();
i'm trying to get amount from cheques and 'cash','created_at' from purchases where 'member_id'=$request->userId, but i get empty cheques when i use this code:
$purchases = \App\Purchase::with(array('cheques'=>function($query){
$query->select('amount');
}))->where('member_id',$request->userId)->get(['cash','created_at']);