Support the ongoing development of Laravel.io →
Database Eloquent Views
Last updated 1 year ago.
0

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
}
Last updated 1 year ago.
0

Cheers Works a treat Kevin

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.