栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何使用Laravel Eloquent创建多个Where子句查询?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使用Laravel Eloquent创建多个Where子句查询?

在Laravel 5.3中从6.x开始仍然适用,您可以使用更细粒度的wheres作为数组传递:

$query->where([    ['column_1', '=', 'value_1'],    ['column_2', '<>', 'value_2'],    [COLUMN, OPERATOR, VALUE],    ...])

就个人而言,我并没有在多个

where
调用中找到用例,但事实是您可以使用它。

自2014年6月起,您可以将数组传递给

where

只要您想要所有

wheres
使用
and
运算符,就可以通过以下方式将它们分组:

$matchThese = ['field' => 'value', 'another_field' => 'another_value', ...];// if you need another group of wheres as an alternative:$orThose = ['yet_another_field' => 'yet_another_value', ...];

然后:

$results = User::where($matchThese)->get();// with another group$results = User::where($matchThese)    ->orWhere($orThose)    ->get();

上面将导致这样的查询:

SELECt * FROM users  WHERe (field = value AND another_field = another_value AND ...)  OR (yet_another_field = yet_another_value AND ...)


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/386458.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号