I have this request
$marche = March::with('attribution')->get()->where('attribution.date_attribution', '2021');
how to format 'attribution.date_attribution' to retrieve only the year ?
I tried with Carbon::parse but I got the following error :
Could not parse 'attribution.date_attribution': Failed to parse time string (attribution.date_attribution) at position 0 (a): The timezone could not be found in the database
CodePudding user response:
Untested, but can you try this:
$marche = March::
with('attribution')
->whereHas('attribution', function($query){
$query->whereYear('date_attribution', '2021');
})
->get();
CodePudding user response:
try with this maybe :
->whereYear('attribution.date_attribution', '2021')
https://laravel.com/docs/8.x/queries#additional-where-clauses