对laravel in 查询的使用方法详解
作者:echo_zhaowei 时间:2024-06-05 09:44:06
今天遇到多条件搜索,其中需要用到in查询,但是laravel不支持 [ 'type', 'in', '1,2,3'] 这样的写法
经过一波百度,也没发现什么好的方法。
其中一种方法是:
$where = function ($query) {$query->whereIn('id', [1,2])->orWhere('d_id', '=', '83');}
这样确实可以解决,是一种解决方法。但我总觉得还有更好的方法,找到了 DB::Raw();
开始我是这样用的
但是这样总会在sql后面出现is null,感觉很奇怪,于是看了下laravel源码
默认我们需要传递三个参数,如:
如果只传一个参数的话,就会出现is null 的情况
所以只需要
这样就可以完美解决,如果有更好的方法 欢迎大家评论。
来源:https://blog.csdn.net/echo_zhaowei/article/details/81906531
标签:laravel,in,查询
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Dreamweaver MX打造弹出“向导”
2009-07-21 12:41:00
![](https://img.aspxhome.com/file/UploadPic/20071/200713110227823s.jpg)
pandas按行按列遍历Dataframe的几种方式
2023-07-04 15:36:05
![](https://img.aspxhome.com/file/2023/1/131391_0s.png)
更改Python的pip install 默认安装依赖路径方法详解
2023-01-05 20:55:28
![](https://img.aspxhome.com/file/2023/1/72921_0s.jpg)
Scrapy框架爬取Boss直聘网Python职位信息的源码
2022-06-30 21:02:47
![](https://img.aspxhome.com/file/2023/1/111931_0s.png)
python 常见的排序算法实现汇总
2023-09-17 13:47:24
![](https://img.aspxhome.com/file/2023/9/131459_0s.png)
Python使用mmap实现内存映射文件操作
2022-04-26 14:37:19
![](https://img.aspxhome.com/file/2023/1/81611_0s.png)
Mac在python3环境下安装virtualwrapper遇到的问题及解决方法
2021-06-22 17:32:38
Express无法通过req.body获取请求传递的数据解决方法
2024-06-05 09:52:06
![](https://img.aspxhome.com/file/2023/8/122388_0s.png)
python中urllib.unquote乱码的原因与解决方法
2023-08-24 14:56:43
Oracle数据加载和卸载的实现方法
2024-01-27 20:19:08
认清区别CSS的类class和id
2007-10-08 12:02:00
python数组和矩阵的用法解读
2023-07-13 07:38:18
![](https://img.aspxhome.com/file/2023/7/110557_0s.png)
sql使用cast进行数据类型转换示例
2024-01-14 07:42:11
vue中的插槽详解
2024-05-03 15:08:50
![](https://img.aspxhome.com/file/2023/4/130224_0s.png)
TensorFlow索引与切片的实现方法
2022-11-08 16:00:12
![](https://img.aspxhome.com/file/2023/7/97517_0s.png)
Python3实现捕获Ctrl+C终止信号
2021-10-17 14:03:55
一文带你了解Go语言标准库math和rand的常用函数
2024-02-22 07:24:24
pandas学习之df.set_index的具体使用
2021-11-12 07:35:20
python groupby函数实现分组后选取最值
2022-06-02 09:27:45
![](https://img.aspxhome.com/file/2023/7/69267_0s.png)
JavaScript常用的返回,自动跳转,刷新,关闭语句汇总
2023-10-21 10:37:27