I have a JSON stored on to my table column valid_dates
:
{"weeks": [8], "endDate": "2022-06-02", "startDate": "2022-07-03"}
I am generating dates range by:
$from = Carbon::now()->addDays(-200);
$from = Carbon::now()->addDays(-200);
$to = Carbon::now();
$past_dates = CarbonPeriod::create($from, $to)->toArray();
$date_strings = [];
foreach ($past_dates as $date) {
$date_strings[] = $date->format('Y-m-d');
}
Now when I have all the date in $date_strings
array according to the format in database, when I try to query it via whereJsonContains()
:
->whereJsonContains('valid_dates->startDate',[$date_strings]) // this doesn't work
Nothing is returned however there are records with matching dates, but the opposite is the case when I try using a single date here as:
->whereJsonContains('valid_dates->startDate','2022-07-03') //this works
I wonder what could I be missing here, I have also checked Laravel docs and found the syntax similar to what I have.
Moreover is there any relaible way to compare data in whereJsonContains()
using operators?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire