I have a complex query such as
$drivers = Drivers::where('somecondition', $request->condition)
->with([
'license' => function($query) {
$query->where('is_active', 1);
},
'license.licenseReport' => function($query) use ($driver_id) {
$query->where('driver_id', $driver_id)
->where('is_active', 1)
->orderBy('created_at', 'DESC');
},
])
->get();
My question is normally i would have $driver_id value set ahead of time but in this scenario i want to use the driver_id as the id from the query itself where the driver_id is the id from the drivers table i am running the query against.
Is this something that is possible where the driver_id being passed into the query is the actual ID from the main drivers table?