I’m trying to use whereRaw with mongodb
$soa_list->where('status', 'FOR OP REQUEST')
->whereRaw("STR_TO_DATE(validity, '%Y-%m-%d') >= ?", Carbon::now());
but I’m getting this error
$or/$and/$nor entries need to be full objects
My validity is string for example ‘January 1, 2024 and I want it to convert first to be able to compare it to todays date.
1
Instead of whereRaw, you might want to use MongoDB’s built-in date handling. You can convert your string date format to a Date object in PHP first
$valiDate = Carbon::createFromFormat('F j, Y', 'January 1, 2024');
$soa_list->where('status', 'FOR OP REQUEST')->where('validity', '>=',$valiDate);
4