My DB column field ("colors") contains an array structured like this:
["1","2","3"]
My current query look like this, simplified for better example:
$value = '1';
$cards = Card::query()
->where('colors', 'like', '%' . $value . '%')
->get();
The problem is, it fetches data from other columns, for example ["5","8","13"]
will match "13"
instead of the strict $value
, which should be "1"
.
How do I write this query the correct way?
used whereJsonContains Method here
value like this then do like that ["1","2","3"]
$cards = Card::query()
->whereJsonContains('colors', '1')
->get();
if value like that [1,2,3] then used like that
$cards = Card::query()
->whereJsonContains('colors', 1)
->get();
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