You can easily achieve that using groupBy() method of the Collection class, but mind that dateTime field won't qualify as array key, so you also need accessor for that:
$events->groupBy('simpleDate');
// returns something like this:
// array(
// '2014-04-18' => array(
// 0 => object(Event)(
// 'incrementing' => true,
// 'timestamps' => true,
// 'exists' => true
// ),
// 1 => object(Event)(
// 'incrementing' => true,
// 'timestamps' => true,
// 'exists' => true
// )
// ),
// '2014-04-10' => array(
// .......
// Event model:
public function getSimpleDateAttribute()
{
return substr($this->attributes['date'], 0, 10); // or whatever you like to process dateTime field
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community