I have Banks
table and separate table with services
$bank = Banks::find(1);
echo $bank->service(1); // print bank with that service (serviceId 1)
It is posible to eager load all banks with service_id =1 ..somewhat like
Bank::with('service(1)')->get();
Thank you in advance
Sure! The with
method accepts a closure to filter eager loading.
Bank::with(array('service' => function($query){
$query->where('id', 1);
}))->get();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With