怎么判断 laravel的model 的数据库为空

如题所述

1.
find --> 返回 object or empty
ex:
$p = Project::find($id);
if(empty($p)) {
dd('project is empty');
}

get --> 返回object , 透过count 方法判断
ex:
$p = Project::where('user_id', '=', $userid)->get();
if($p->count() == 0) {
dd('project is empty');
}
温馨提示:答案为网友推荐,仅供参考
相似回答