我收到一个型号。该模型可以有两种类型。说它可以是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.
}
}
答案 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.
}
}