Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kylym1631's avatar

How can I use the policy method inside the table method in Resource class?

This is my company policy view method

public function view(Admin $user, Company $company): bool
    {
        return $user->hasRole('super-admin') ||
               ($user->hasRole('manager') && $company->managers()->where('admins.id', $user->id)->exists());
    }

I could do like

return $table
           ->modifyQueryUsing(function (Builder $query): Builder {
                return $query->whereHas('managers', function ($query) {
                    $query->where('admins.id', auth()->id());
                });
            })

but I would be repeating myself. How can I use the policy view method to query in the table method?

0 likes
3 replies
martinbean's avatar

@kylym1631 Can you update the formatting of your post? It’s quite difficult to see what you’re asking, and what code you’re trying to show us.

Please or to participate in this conversation.