简体   繁体   English

刀片模板中的Laravel嵌套循环

[英]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 在此处阅读有关使用QueryBuilder的更多信息

In your view, do as follows: 您认为,请执行以下操作:

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

Read more about blades here 在此处阅读有关刀片的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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