I have this as the basic of what i want to do but the constraint is not applying
$this['subs'] = Cat::with([
'children' => function($query) {
$query -> where('parent_id', 0);
}
]) -> get();
I have this as the basic of what i want to do but the constraint is not applying
$this['subs'] = Cat::with([
'children' => function($query) {
$query -> where('parent_id', 0);
}
]) -> get();
the one you are looking for, is whereHas
, like this:
$this['subs'] = Cat::whereHas('children', function ($query) {
$query->where('parent_id',0);
})->get();
putting a query in with
just scopes the relationships it queries, not the record set cat
itself.