为什么 Laravel 中 in 查询只支持 whereIn () 这种写法呢?

为什么laravel中in查询只支持whereIn()这种写法呢?
而不支持
$where[] = ['o.pay_type', [1, 5]]
或者
$where[] = ['o.pay_type', 'in', [1, 5]]
这种数组的写法呢?只能用whereIn这种写法不是很不方便吗?

《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 11

$where[] = [function($q)use($ids){ $q->whereIn('id',$ids); }];

2年前 评论

$where[] = [ 'in' => ['id' => [1,2,3] ] ]

5年前 评论
cc1997 4年前
limuxia 2年前

@tom2333 还有这么骚的操作??哈哈

5年前 评论

@tom2333 好像不对呀,我这边试一下还是不行,只能搜索出‘’1“对应的记录,后面的还是没有查出来的

5年前 评论
lauwen

@tom2333 无效 laravel5.7

4年前 评论

laravel5.8 无效

4年前 评论

$where['in'] = []; $where['in']['sub_order_id'] = $subOrderIds;

$in = []; if (isset($where['in'])) { $in = $where['in']; unset($where['in']); } $query = $this->dbDomain->table(self::TABLE) ->where($where); if (!empty($in)) { foreach ($in as $name => $value) { $query->whereIn($name, $value); } } $query->where(self::COL_IS_DELETED, "=", 0) ->orderBy(self::COL_CREATED_TIME, 'desc'); $total = $query->count(); if ($page != 0) { $query->forPage($page, $pageSize); } $subOrders = $query->get($columns)->all();

3年前 评论

因为优雅的laravel觉得你会觉得这样不优雅

3年前 评论

$where[] = [ function ($query) use ($id) { $query->whereIn('id', $id); }, ];

2年前 评论

$where[] = [function($q)use($ids){ $q->whereIn('id',$ids); }];

2年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!