在使用Laravel Eloquent模型时,我们可能要判断取出的结果集是否为空,但我们发现直接使用is_nullempty是无法判段它结果集是否为空的。

var_dump之后我们很容易发现,即使取到的空结果集, Eloquent仍然会返回Illuminate\Database\Eloquent\Collection对象实例。
其实,Eloquent已经给我们封装几个判断方法。

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

参考网站:http://stackoverflow.com/questions/20563166/eloquent-collection-counting-and-detect-empty

最新文章

  1. shiro 实现单用户登录,一个用户同一时刻只能在一个地方登录
  2. 用css3实现各种图标效果(2)
  3. git alias和gitconfig配置
  4. 通俗易懂------this指向
  5. 「Ruby && Sqlite3」How to install sqlite3 for ruby? (solve: sqlite-ruby no such file...)
  6. linux shell 中的位置变量
  7. java-脚本-编译-注解
  8. 使用Rails 4.2+ 测试异步邮件系统
  9. oracle学习 三(持续更新中)
  10. Longest Consecutive Sequence——Leetcode
  11. 关于Linux的缓存内存 Cache Memory详解<转>
  12. ueditor插件 -- 插入填空题
  13. 2013第四届蓝桥杯决赛Java高职高专组题目以及解法答案
  14. Linux下高并发socket最大连接数
  15. 【博客开篇】服务器配置:Windows2008R2+PHP5.6+SQLServer2008(X64)
  16. 第四章 HTML5概述
  17. centos7上编译安装mysql5.6
  18. 【WPF】两则动画效果
  19. 探讨android更新UI的几种方法
  20. eclipse+gnuarm+使用报错

热门文章

  1. opencv学习笔记(五)镜像对称
  2. ping 有端口的ip
  3. git linux
  4. 二、JavaScript语言--JS基础--JavaScript进阶篇--函数
  5. 错误解决error while loading shared libraries: libXXX.so.X: cannot open shared object file: No such file
  6. 版本引发的血案check the manual that corresponds to your MySQL server version for the right syntax
  7. 【转】reduce端缓存数据过多出现FGC,导致reduce生成的数据无法写到hdfs
  8. js:语言精髓笔记8--对象系统
  9. 水题 Codeforces Round #300 A Cutting Banner
  10. 在visual studio中使用git版本系统(zz)