Modify Query Using nested relationship

Hi, I have an institution resource, every institution belongs to a state and every state belongs to an admin.

admin ----has many---> states ---has many----> institutions

I want to only show the institutions that belong indirecly to the currently logged in admin, this is what I attempted but it didn't work:

            ->modifyQueryUsing(function (Builder $query) {
                return $query->withWhereHas('state.admin', function (Builder $filter) {
                    $filter->where('id', auth()->id());
                });
Was this page helpful?