829 0 0 0
Last Updated : 2025-04-29 00:51:02
Some time, you may need to get a record with some relationship and at the same time you need to get an inner relationship to that relationship and so forth. Here is the key : $records->with(['bill', 'bill.sponsor', 'bill.sponsorSenator', 'bill.sponsor.actions']).
$records = new BillEventModel();
$records = $records->newQuery();
$records->where('eventType','federal');
$records = $records->with(['bill', 'bill.sponsor', 'bill.sponsorSenator'])->groupBy('bill_id')->orderBy('date', 'desc'); //Use this to add the relatioship and inner ones as well
$recordsCount = $records->get()->count();
$records = $records->paginate(50);