Check if a class is a Model in Laravel 5

a 夏天 提交于 2019-12-05 23:31:32

You may need the full namespace. When I do get_parent_class() on one of my models, it returns Illuminate\Database\Eloquent\Model. So use this instead:

$model = 'App\\' . Str::studly(Str::singular($what));
if (!is_subclass_of($model, 'Illuminate\Database\Eloquent\Model')) {

You can check if your object is an instance of a model with instanceof:

$article = new \App\Article();

if ($article instanceof \Illuminate\Database\Eloquent\Model) {
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!