我一直在使用Laravel 5.4的口才,並且遇到了問題。使用Laravel的口才在JSON列中搜索
我有一個數據庫表,名爲的帖子,並在那一列名爲template_ids
。它在json_encoded
格式一樣存儲值:
["1","25","48"]
現在,我想基於ID的陣列上的過濾器適用於我的查詢:
$id_access = array:3 [
0 => "1"
1 => "3"
2 => "48"
]
我所試圖做的是搜索如果數據庫列中存在$id_access
值,則template_ids
。
我想:
Post::where('accessable_to',1)->whereIn('template_ids', $template_access_array)->paginate(3);
而且,我想:
Post::where('accessable_to',1)->whereRaw("JSON_CONTAINS(template_ids, ".$template_access.")")->paginate(3);
已經看到this,但它不是爲我工作。
可能是這樣https://stackoverflow.com/questions/41942374/json-search-in-laravel-eloquent會幫助你。此外,您需要將您的列template_ids的數據類型更改爲mysql中的JSON –
您遇到的任何錯誤? –
@Alankar更多我已經添加了鏈接。我看到這篇文章 –