Laravel / Eloquent:如何查询包含数组的JSONB字段?

时间:2020-09-04 08:58:57

标签: laravel

我具有这样的JSONB结构,请注意adults是一个数组,我需要查询该数组中的每个成年人:

"passengers" => [
    "adults" => [
        "count" => 2,
        "persons" => [
            [
                "name" => "foobar-adult",
                "age" => date("Y") - 1975,
                "birth_date" => "01-01-1975",
            ],
            [
                "name" => "other adult",
                "age" => date("Y") - 1978,
                "birth_date" => "02-02-1978",
            ],
        ],
    ]
]

,我需要按成人的名字查询外勤乘客。这是我的尝试:

Trip::where("passengers->adults->persons->name", "LIKE", "%foo%")->get();

但是,尽管有乘客叫“ foobar”,查询仍返回空。

0 个答案:

没有答案