比较模型类型Laravel

时间:2017-05-21 11:06:32

标签: php laravel eloquent compare laravel-5.4

我收到一个型号。该模型可以有两种类型。说它可以是App\Models\User App\Models\Resource

我想查看它是哪种类型?目前我正在使用instanceof,但没有运气。

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.
    }
}

1 个答案:

答案 0 :(得分:0)

您上课的路径应为\App\Models\User

use App\Models\User;

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

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