[转]Laravel - Where null and Where not null eloquent query example
本文转自:
https://hdtuto.com/article/laravel-where-null-and-where-not-null-eloquent-query-example-
if you are a starter or learner laravel then you have in mind how to check where null or where not null condition using laravel eloquent model when you are writing eloquent query. if you write query for SQL then it is very easy syntax and families with where null and not null condition.
In this small tutorial i will let you know how you can write query for where null and where not null condition. here i will write core SQL query and then convert it into laravel query builder using db. So just see bellow example and see how it is works.
we have following solution on SQL and Laravel query builder:
1) IS NULL = whereNull()
2) IS NOL NULL = whereNotNull()
Where Null Query:
SQL Query:
SELECT * FROM users
WHERE name IS NULL;
Laravel Query:
DB::table('users')
->whereNull('name')
->get();
Where Not Null Query:
SQL Query:
SELECT * FROM users
WHERE name IS NOT NULL;
Laravel Query:
DB::table('users')
->whereNotNull('name')
->get();
I hope you found your best solution...
[转]Laravel - Where null and Where not null eloquent query example的更多相关文章
- SQL SERVER 中is null 和 is not null 将会导致索引失效吗?
其实本来这个问题没有什么好说的,今天优化的时候遇到一个SQL语句,因为比较有意思,所以我截取.简化了SQL语句,演示给大家看,如下所示 declare @bamboo_Code varchar(3); ...
- null和空 not null
所谓的NULL就是什么都没有,连\0都没有,\0在字符串中是结束符,但是在物理内存是占空间的,等于一个字节,而NULL就是连这一个字节都没有.在 数据库里是严格区分的,任何数跟NULL进行运算都是NU ...
- [Guava官方文档翻译] 2.使用和避免使用null (Using And Avoiding Null Explained)
本文地址:http://www.cnblogs.com/hamhog/p/3536647.html "null很恶心." -Doug Lea "这是一个令我追悔莫及的错误 ...
- SQL - 将NULL设置为 NOT NULL
在有些时候,我们在创建表的时候,会忘掉设置某一个列的属性,比如忘了设置为非空,但是默认情况下系统会自动的设置为NULL.这样我们该怎样通过语句设置呢?? 例如有一个表,其中的一个属性为WM CHAR( ...
- xxx==null和xxx.equals(null)的区别
如果xxx不是null的话,xxx==null将返回false,如果xxx是null的话,xxx将返回ture 而对xxx.equals(null)而言,他将永远返回false,因为如果xxx不是nu ...
- 关于MSSQL中IS NULL和IS NOT NULL的问题
在SQL语句中我们一般会避免写IS NULL和IS NOT NULL,因为这样优化器不会使用索引. 但经过一系列测试发现这句话并不完全对,因为有时候也会使用索引. 语句: select * from ...
- 3.is null和is not null
3.WHERE中使用is null和is not null //查询工资是null空值的人 select * from person where salary is null; //查询工 ...
- ORACLE查询优化之is null和is not null优化
最近工作的时候遇到了比较大的数据查询,自己的sql在数据量小的时候没问题,在数据量达到300W的时候特别慢,只有自己优化sql了,以前没有优化过,所以记录下来自己的优化过程,本次是关于is null和 ...
- 面试题((A)null).fun()——java中null值的强转
面试题分享 public class A {public static void fun1() { System.out.println("fun1"); } public voi ...
随机推荐
- noip第30课资料
- Debian 8.x / Ubuntu 16.04.x 搭建 Ghost 教程
Ghost 是一款使用 Node.js 开发的博客系统,相对于使用 PHP 开发的 WordPress 更轻巧友好,所以本站已经从 WordPress 切换至 Ghost,本文介绍在 Debian 8 ...
- [XAF] Llamachant Framework Modules
Llamachant Framework Modules 最近更新 2018-08-22 *变更:我们从所需的模块列表中删除了审计跟踪模块.如果要在应用程序中使用Audit Trail功能,请将Aud ...
- WordPress图片或文字添加水印插件:Easy Watermark
Easy Watermark可以在上传到WordPress媒体库时自动为图像添加水印.您也可以手动为现有图像添加水印(一次全部或每个图像).水印可以是图像,文本或两者. 插件功能 图像水印可以是jpg ...
- Drools规则引擎入门指南(一)
最近项目需要增加风控系统,在经过一番调研以后决定使用Drools规则引擎.因为项目是基于SpringCloud的架构,所以此次学习使用了SpringBoot2.0版本结合Drools7.14.0.Fi ...
- node.js服务器搭建
//1.导入http 核心模块 const http = require("http"); //2.调用http.createServer 方法,创建一个web 服务器对象 con ...
- [Swift]Xcode标记:MARK、TODO、FIXME
1. MARK MARK一定要大写.其又叫做代码标注,我们可以使用它来添加一些说明文字.同时可以选择其上方是否需要显示分割线. // MARK: - 说明文字,带分割线 // MARK: 说明文字,不 ...
- rabbitmq在ios中实战采坑
1. rabbitmq在ios中实战采坑 1.1. 问题 ios使用rabbitmq连接,没过多久就断开,并报错.且用android做相同的步骤并不会报错,错误如下 Received connecti ...
- java:当字符串为We Are Happy.经过替换之后的字符串为We%20Are%20Happy
方法一: public class Solution { public String replaceSpace(StringBuffer str) { String a=str.toString(); ...
- idea导入maven项目 傻瓜都能看懂
1.找到你需要导入的项目 2.打开idea ------------------------------------------------------------------------------ ...