laravel 查询数据返回的结果

laravel查询数据返回的结果

在插入数据库的时候,发现查询数据返回的结果是一个对象;即使是空数据 返回的不是true或者false

那么要判断该结果是否查询有结果 该如果呢?

学习源头:

https://douyasi.com/laravel/eloquent_collection_detect_empty.html

https://stackoverflow.com/questions/20563166/eloquent-collection-counting-and-detect-empty

不能用is_set() empty() 来判断 因为不管成功与否 都是true

$result = Model::where(...)->get();
//不为空则
if ($result->first()) { } 
if (!$result->isEmpty()) { }
if ($result->count()) { }

猜你喜欢

转载自www.cnblogs.com/djwhome/p/8986510.html