我正在尝试获取时间表,将 JSON 列数据与 Laravel 项目中的以下代码进行比较:
$schedules = Schedule::where('schedule_with->company_person', $contact_company_person->id)->get();
Run Code Online (Sandbox Code Playgroud)
这会生成如下 SQL 查询:
select * from `schedules` where `schedule_with`->'$."company_person"' = 1;
Run Code Online (Sandbox Code Playgroud)
虽然这适用于 MYSQL 5.7 及更高版本,但不适用于 MARIADB 10.5。但 MARIADB 从 10.2 开始已经支持 JSON 列。对于 MARIADB,以下查询有效:
select * from schedules where JSON_Value(schedule_with, "$.company_person") = 3;
Run Code Online (Sandbox Code Playgroud)
Laravel 是否需要进行一些配置更改才能使其正常工作?
我知道它可以通过原始查询来实现,我很好奇我错过了什么?
谢谢你,