0
I’m having trouble grouping data together for different days. I have some reports registered and with the standard Created_at and Updated_at I’d like to show these communiqués Separated day by day.. VIEW
@foreach($messages as $message)
<li class="time-label">
<span class="bg-red">
{{ $message->updated_at }}
</span>
</li>
<li>
<i class="fa fa-envelope bg-blue"></i>
<div class="timeline-item">
<span class="time"><i class="fa fa-clock-o"></i> </span>
<h3 class="timeline-header"><a href="#"></a> ...</h3>
<div class="timeline-body">
{{ $message->message }}
</div>
<div class="timeline-footer">
<a class="btn btn-primary btn-xs">...</a>
</div>
</div>
</li>
@endforeach
ATTEMPT TO GROUP BY DAY CONTROLLER
public function timeline(Request $request){
$messages = Message::where('type_send', 1)->groupBy(function($date){
return Carbon::parse($date->created_at)->format('D');
});
return view('messages.timeline', compact('messages'));
}
EDIT CONTROLLER
public function timeline(Request $request){
$messages = Message::orderBy('created_at', 'desc')->get()
->groupBy(function($date) {
return Carbon::parse($date->created_at)->format('M d'); // grouping by day
});
return view('messages.timeline', compact('messages'));
}
DUMP IN $messages IN VIEW
I would now like to list the messages separately by month, what would be the solution?
VIEW I managed to show the day of the month but now I want to list in the messages with the same day of the month
<ul class="timeline">
@foreach($messages as $message)
<li class="time-label">
<span class="bg-red">
{{ $message->first()->updated_at }}
</span>
</li>
<li>
<i class="fa fa-envelope bg-blue"></i>
<div class="timeline-item">
<span class="time"><i class="fa fa-clock-o"></i> </span>
<h3 class="timeline-header"><a href="#"></a></h3>
<div class="timeline-body">
</div>
<div class="timeline-footer">
<a class="btn btn-primary btn-xs">...</a>
</div>
</div>
</li>
@endforeach
</ul>
So, the error is the following: it expects a text parameter (or multiple columns separated by comma), what you did is not supported If you want to group by day the strategy has to be another because the way you also did is missing some things in this SQL (Builder)
– novic
I’m all day trying to do this and I can’t, which I should change?
– Gabriel Alves
Which SQL you need to do?
– novic
take a look at Edit @Virgilionovic
– Gabriel Alves
Let’s explain what you did, brought a mass of data in
SQL
and then in classCollection
grouped the data, that is, had two effort (maybe only with SQL would already work). you want to group by month? or month and Year? I’m still in doubt what you really want, if you could put a current example of its basis and what outcome awaits?– novic
I want to list all posts separately by day of the month, show once the day of the month and all posts for that day of the month. as the other Edit mine with the result of the preview, if you repair @Virgilionovic on Mar 21 day I have 6 messages and on Mar 22 day I have 1 messages
– Gabriel Alves
So it seems to me you have the result just can’t print? in your View is like? or did nothing there?
– novic
@Virgilionovic My view is like the print I showed you, I just managed to put the days of the month that have messages, but not able to put the messages inside, would I have to use a foreach inside another foreach? Look at Edit
– Gabriel Alves