简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM