modifyQueryUsing with a role
hi guys, I have this query in the table function in my productResource but I only want to apply it when the user does not have the 'Admin' role, is there a way to do it?
->modifyQueryUsing(fn (Builder $query): Builder => $query->where('country_id', auth()->user()->country_id))
1 Reply
I found a solution:
->modifyQueryUsing(fn (Builder $query): Builder =>
$query->when(auth()->user()->hasRole('Admin') === false, function ($query) {
return $query->where('country_id', auth()->user()->country_id);
}))