我的 whereJsonContains 不起作用(Laravel 5.8)

我的 laravel 查询有问题。

现在我使用这样的查询:

$courses = Course::whereJsonContains('schedule->day', 1)->get();

它不起作用。

我正在使用 postgreSql 9.6,我的数据库和原始查询看起来像这样

http://sqlfiddle.com/#!17/88fd2/1/0

我想选择一天有时间表的班级= 1


白衣染霜花
浏览 311回答 4
4回答

ibeautiful

如果将列定义为schedule->day,MySQL 假定这是一个整数数组。在您的情况下,它是一个对象数组,因此您必须定位父数组并在第二个参数中添加您要查找的属性名称。像这样:$courses = Course::whereJsonContains('schedule', ['day' => 1])->get();

幕布斯6054654

我解决了$courses = Course::whereJsonContains('schedule', [['day' => '1']])->get();

HUWWW

如果您正在查询您不需要使用的值whereJsonContains,只需使用常规where查询,例如:$courses = Course::where('schedule->day', 1)->get();`如果要检查dayJson 中是否存在,请使用whereJsonLength例如:$courses = Course::whereJsonLength('schedule->day', '>', 0)->get();

莫回无

我解决了$products=ProductShop::active()           ->whereJsonContains('tag', [['value' => "tampa"]])->get();
打开App,查看更多内容
随时随地看视频慕课网APP