Laravel Nested Loop in blade Templating

I am building a futsal league website where fixtures and results are to be displayed. The Result Model is like this

class Result extends Model {

//
protected $fillable = ['team_1', 'team_2', 'goals_1', 'goals_2', 'date', 'mom'];

}

Is there a way that I can loop through this data in blade and group by date?

Thanks in advance

Upvotes: 0

Views: 557

Answers (1)

SebHallin
SebHallin

Reputation: 891

In your controller, you can do as follows:

return view('yourView', [
    'variable' => Result::groupBy('date')->get()
]);

Read more about using models here

Read more about using QueryBuilder here

In your view, do as follows:

@foreach($variable as $row)
    {{$row->date}}
@endforeach

Read more about blades here

Upvotes: 1

Related Questions