JSON Search in laravel eloquent

后端 未结 2 1215
遇见更好的自我
遇见更好的自我 2021-02-05 19:11

I am storing destinations field as json type in mysql

example column value [\"Goa\", \"Moonar\", \"Kochi\"]

I

2条回答
  •  既然无缘
    2021-02-05 19:55

    Probably forced to use a partially raw query like:

    use DB; (top of file definition)

    DB::table('packages')->whereRaw('json_contains(destinations, \'["Goa"]\')')->get();

    And if you have a model:

    Package::whereRaw('json_contains(destinations, \'["' . $keyword . '"]\')')->get();

    assuming your query above works in SQL.

提交回复
热议问题