You have a column named the exact same thing as a magic method would be able to check. In Laravel if you use where{Field}() then it will try to resolve the 'where field'. e.g. ->whereName('John') will resolve to ->where('name', 'John') In your example I would consider using ->whereBetween('date', [$start, $end]) if changing the database is out of the question..
How to filter collection based on date comparison ?
I have a period table that has: a start column of type date an end column of type date a current column of type boolean (only one period has this current column set to 1)
Then I have an events table with a date column of type date
In a controller I want to get a collection of events whose date column is betwen the start and the end of the current period i.e. the period with 1 in column current.
I do this
$period=Period::where('current',1)->get();
$start=$period[0]->start;
$end=$period[0]->end;
$events=EventResource::collection(Event::whereDate('date','>=',$start)->whereDate('date','<=',$end))->get();
The last line make the controller crash with this message.
"message": "Call to undefined method Illuminate\Database\Eloquent\Builder::mapInto()", "exception": "BadMethodCallException",
Whatis wrong here?
$events=EventResource::collection(Event::where('date','>=',$start)->where('date','<=',$end)->get());
was the good expression. Note the closing parenthesis at the end.
Please or to participate in this conversation.