【问题标题】:Laravel Nested Loop in blade Templating刀片模板中的 Laravel 嵌套循环
【发布时间】:2016-07-14 16:31:46
【问题描述】:

我正在建立一个五人制足球联赛网站,用于显示赛程和结果。结果模型是这样的

class Result extends Model {

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

}

有没有一种方法可以循环遍历刀片中的这些数据并按日期分组?

提前致谢

【问题讨论】:

  • 是的,总会有办法的。
  • @Chay22 怎么样?我知道嵌套的 foreach 可以做到,但我不知道如何使用嵌套的 foreach 来获得我想要的

标签: php laravel-5 nested-loops laravel-blade


【解决方案1】:

在您的控制器中,您可以执行以下操作:

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

Read more about using models here

Read more about using QueryBuilder here

在您看来,请执行以下操作:

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

Read more about blades here

【讨论】:

    猜你喜欢
    • 2015-12-01
    • 2022-01-23
    • 2021-05-05
    • 2019-03-02
    • 1970-01-01
    • 2020-09-26
    • 1970-01-01
    • 2017-09-26
    • 2018-12-21
    相关资源
    最近更新 更多