I want my data grouped by date and sort it. Then I want it to pass it in an array that looks like so:
This is my query:
- $events = Event::with('specifications', 'users', 'location')
- ->join('locations','location_id', '=', 'events.location_id')
- ->where('locations.zip', '=', $data['location'])
- ->where('date', '>=', $data['date'])
- ->orderBy('date')
- ->get();
It gives me a array like this:
- [0] => Event Object
- (
- [...]
- [attributes:protected] => Array
- (
- [id] => 1
- [title] => yyy
- [image] => img/event/default.jpg
- [desc] => Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing eli
- )
- [....]
- )
- [1] => Event Object
- (
- [...]
- [attributes:protected] => Array
- (
- [id] => 2
- [title] => xxx
- [image] => img/event/default.jpg
- [desc] => Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing eli
- )
- [....]
- )
but I want a array that is sortet and grouped like this (you know what i mean ;) ):
- [0] = array(
- [0] => date = xx.xx.xxxx
- [1] => array (
- Event Object ()
- )
- )
- [1] = array(
- [0] => date = yy.yy.yy
- [1] => array (
- Event Object ()
- )
- )
So that i can loop through the array in two loops. one for the date and one for the object. like this bad example:
- foreach($event_by_date as $evendate){
- <h2>$eventdate</h2>
- foreach($eventdate as $event){
- $event->name
- $event->desc
- ... etc ...
- }
- }
how i do this with laravel and eloquent queries? i'm not a laravel/php ninja ;)