laravel中whereJsonContains跟whereJsonDoesntContain的区别浅析
Laravel  /  管理员 发布于 2年前   738
laravel中whereJsonContains跟whereJsonDoesntContain的区别浅析
中文官网上基本都是whereJsonContains的信息,而whereJsonDoesntContain是信息特别少,
我刚好又需要查找数据库中字段不包含某个值或多个值的信息功能,所以直接上git里面搜了一下
看到了所以记录一篇文章,可能别人需要
Laravel 也支持查询 JSON 类型的字段(仅在对 JSON 类型支持的数据库上)。
目前,本特性仅支持 MySQL 5.7、PostgreSQL、SQL Server 2016 以及 SQLite 3.9.0 (with the JSON1 extension)。使用 -> 操作符查询 JSON
都是作为查询 json 数据,一个包含一个反之
whereJsonDoesntContain是5.6*版本发布的
whereIn()与whereJsonContains()相反
whereIn()检查列值是否存在于用户提供的值中
whereJsonContains()检查列中是否存在用户提供的值。
当列值为数组时,列选择器将不包含->。
所以Laravel不会知道用户正在查询JSON列。
whereJsonContains
Model::whereJsonContains('options->languages', 'en')->get(); # 字段是数组 包含
例子:字段需数组 [1,2,3] 查询包含某一个值或多个值的数据
Models\NewsList::select('id','title','newstypeone',
DB::raw('(select `youhuipy` from `lara_23_cbb_company_CreditCard` as a where a.`id`=`lara_55_cbb_NewsList`.`bankid`) as youhuipy'))
->whereJsonContains('newstypeone', $row['newstypeone'])->orderBy('id','desc')->take(5)->get()->toArray();
whereJsonDoesntContain
Model::whereJsonDoesntContain('options->languages', 'en')->get(); # 字段是数组, 不包含
例子:反之
Models\NewsList::select('id','title','newstypeone',
DB::raw('(select `youhuipy` from `lara_23_cbb_company_CreditCard` as a where a.`id`=`lara_55_cbb_NewsList`.`bankid`) as youhuipy'))
->whereJsonDoesntContain('newstypeone', $row['newstypeone'])->orderBy('id','desc')->take(5)->get()->toArray();
希望对你有用
博主 在
2023年国务院办公厅春节放假通知:1月21日起休7天中评论 @ xiaoB 你只管努力,剩下的叫给天意;天若有情天亦老,..xiaoB 在
2023年国务院办公厅春节放假通知:1月21日起休7天中评论 会不会春节放假后又阳一次?..BUG4 在
你翻墙过吗?国内使用vpn翻墙可能会被网警抓,你需了解的事中评论 不是吧?..博主 在
go语言+beego框架中获取get,post请求的所有参数中评论 @ t1 直接在router.go文件中配就ok..Jade 在
如何在MySQL查询中获得当月记录中评论 Dear zongscan.com team, We can skyroc..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号