Hi guys
I get following error:
ErrorException in Collection.php line 257:
Illegal offset type
if I execute following code:
return Pool::all()->groupBy('created_at'); // Pool is a Eloquent model.
This only happens if I try to group by a carbon date attribute.
If I execute:
return Pool::all()->groupBy('id');
or even a non existing attribute:
return Pool::all()->groupBy('foo');
then no exception is thrown.
I tried it on different models.
I'm on version 5.0.27
I also tried it on another app which sits on version 5.0.22 - same error.
Do I miss something?
That works:
return Pool::all()->groupBy(function($pool) {
return $pool->created_at->toDateTimeString();
});
Is the error above expected behaviour and I have to group it with a closure?
Yeh, you will need to use a closure.
Thanks Graham for your fast answer!
Thanks @strebl :+1:
Most helpful comment
That works:
Is the error above expected behaviour and I have to group it with a closure?