Desired boot with options - laravel

I have a Banks table and a separate table with services

 $bank = Banks::find(1); echo $bank->service(1); // print bank with that service (serviceId 1) 

You can load all banks using service_id = 1 ... as

 Bank::with('service(1)')->get(); 

Thank you in advance

+5
source share
2 answers

Of course! The with method accepts a close to filter the desired load.

 Bank::with(array('service' => function($query){ $query->where('id', 1); }))->get(); 
+8
source

Use WhereIn for your model, and you must pass any number inside the array.

 $Data = Banks::whereIn('service_id ', array(1, 2, 3))->get(); var_dump($Data); 

I use var_dump and you have to choose your own coloumn to get your needs.

Docs: Eloquent , Advance Where

0
source

Source: https://habr.com/ru/post/1209869/


All Articles