Sunday, May 21, 2017

Comparing Model types Laravel

I receive a single model. This model can be of two types. Say Either It can be App\Models\User OR App\Models\Resource

I want to check which type it is ? Currently I am using instanceof but no luck.

public function someFunction($result)
{
    //result can be either User model or Resource model.

    if( $result instanceof App\Models\User)
    {
       //do soemthing for user.
    }
    else{
       //do something for resource.
    }
}



via Nauman Zafar

Advertisement