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()) { }

 

相关文章:

  • 2022-12-23
  • 2021-06-06
  • 2021-11-30
  • 2022-12-23
  • 2021-08-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案