$rosters = EventRosters::where('event_id', $event_id)
->whereJsonContains('players', $user_id)
->whereNull('deleted_at')
->get();
The eloquent query above seems to only work when there is a single item in the 'players' json array.
The data stored in the database looks as follows:
[1]
vs ["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"]
?
I am pretty new to Laravel and have been struggling with this one a bit.
The data types have to match:
// [1, 2]
->whereJsonContains('players', 1) // Works.
->whereJsonContains('players', '1') // Doesn't work.
// ["1", "2"]
->whereJsonContains('players', '1') // Works.
->whereJsonContains('players', 1) // Doesn't work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With