3
I have the following code snippet
$sectors = Sector::where('company_id', $id)
->where('status', '0')
->with('charges.levels')
->get();
and need 3 conditions
- Status of sector be it 0
- Status of cartoons be it 0
- Status of levels be it 0
So I’d like to know:
- How do I use a WHERE that searches for Charge 0 status and level 0 status being that they are in a nested
with
:->with('charges.levels')
The code follows the hierarchy that:
- A sector has one or more positions and a position belongs to one sector only.
- A post has one or more levels and a level belongs to one post only.
Taking into account that I want to bring all levels where the level is status 0, the status 0 position and the status 0 sector
I think this is what you want: https://laravel.com/docs/5.5/eloquent-relationships#constraining-Eager-loads
– Miguel
I can not comment yet so I will comment here, could post your models, Migrations if use and appropriate relationships for analysis?
– Eduardo Gonçalves
Which version of the Laravel you are using?
– Alvaro Alves