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

murilo's avatar
Level 10

laravel policy , get other column customer_id

in laravel policy . it checks by default the user_id, ButI need to check the customer_id ( not the user_id ). here I call my policy -

$gate = Gate::policy(PropMessage::class, PropMessagePolicy::class); 
response = $gate->inspect('messageProperty', $prop);  

and my policy

class PropMessagePolicy
{
    public function messageProperty(UserCustomer $customer, Prop $prop) {

it is giving this error -


"message": "Illuminate\\Translation\\PotentiallyTranslatedString::__toString(): Return value must be of type string, null returned",
    "exception": "TypeError",

the problem is the column name that must to check is customer_id , not user_id ( the default ). how could I specify that I want to check client_id , instead user_id ?

0 likes
1 reply
vincent15000's avatar

You shouldn't change the first argument of the policy, it's always the connected user, no matter if it's a user or a customer or a member or some other role.

Unless you have 2 different tables with users ?

Please or to participate in this conversation.