Php 集合中的Laravel嵌套Foreach循环

Php 集合中的Laravel嵌套Foreach循环,php,laravel-5,foreach,laravel-blade,Php,Laravel 5,Foreach,Laravel Blade,我有以下收藏: 截图: 我想做的是使用blade模板按州返回3行中的每个州立大学。例如: 马萨诸塞州 学院1学院2学院3 佛罗里达州 学院1学院2学院3 学院4 我尝试了其他帖子中许多不同的建议示例,但没有找到解决方案 以下是我尝试过的: Here is what I have tried: @foreach ($colleges as $college) @foreach($college as $state) <h1 style="c

我有以下收藏:

截图: 我想做的是使用blade模板按州返回3行中的每个州立大学。例如:

马萨诸塞州

学院1学院2学院3

佛罗里达州

学院1学院2学院3

学院4

我尝试了其他帖子中许多不同的建议示例,但没有找到解决方案

以下是我尝试过的:

Here is what I have tried:

     @foreach ($colleges as $college)
      @foreach($college as $state)
        <h1 style="center">{{ $state[0]['College']['state'] }}</h1>
      <ul class="nospace clear">
        <li class="one_quarter first">
          <a href="#">
            <img src="{{ asset('storage/' . $state[0]['College']['logo'])  }}" alt="{{ $state[0]['College']['college'] }}" />
          </a>
          <h3 class="center">{{ $state[0]['College']['college'] }}</h3>
        </li>
      </ul>
      @endforeach
@endforeach
以下是我尝试过的:
@foreach($colleges作为$college)
@foreach(学院为$state)
{{$state[0]['College']['state']}
  • {{$state[0]['College']['College']}
@endforeach @endforeach
任何帮助都将不胜感激


Greg

从您的收藏截图来看,它具有以下结构:

[
  state
    college
    college

  state
    college
    college
    college

  ...
]
因此,如果您在
$states
集合上使用
foreach
,将
$key
作为州名称,将
$value
作为该州的学院集合,则可以执行以下操作:

@foreach ($states as $state => $colleges)
    <h1 style="center">{{ $state }}</h1>

    <ul class="nospace clear">
        @foreach ($colleges as $college)
            <li class="one_quarter first">
                <a href="#">
                    <img src="{{ asset('storage/' . $college->logo) }}" alt="{{ $college->college }}" />
                </a>
                <h3 class="center">{{ $college->college }}</h3>
            </li>
        @endforeach
    </ul>
@endforeach
@foreach($state为$state=>$colleges)
{{$state}}
    @foreach($colleges作为$college)
  • {{$college->college}
  • @endforeach
@endforeach
您决定让他人为您编写代码,而不是显示您实际尝试的内容。你可能应该雇佣一个开发者。