本文介紹了whereJsonContains Laravel 5.6 不起作用?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
$rosters = EventRosters::where('event_id', $event_id)
->whereJsonContains('players', $user_id)
->whereNull('deleted_at')
->get();
上面的 eloquent 查詢似乎只在 'players' json 數組中有單個項目時才有效.
The eloquent query above seems to only work when there is a single item in the 'players' json array.
存儲在數據庫中的數據如下所示:[1]
vs ["1","2"]
The data stored in the database looks as follows:
[1]
vs ["1","2"]
whereJsonContains 僅在數據庫中看到 [1]
時才起作用,而在看到 ["1","2"]
時不起作用,有什么原因嗎?
Is there a reason the whereJsonContains is only working when it sees [1]
in the db but not when it sees ["1","2"]
?
我對 Laravel 還很陌生,并且一直在努力解決這個問題.
I am pretty new to Laravel and have been struggling with this one a bit.
推薦答案
數據類型必須匹配:
// [1, 2]
->whereJsonContains('players', 1) // Works.
->whereJsonContains('players', '1') // Doesn't work.
// ["1", "2"]
->whereJsonContains('players', '1') // Works.
->whereJsonContains('players', 1) // Doesn't work.
這篇關于whereJsonContains Laravel 5.6 不起作用?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!