laravel blade 2Dim array output

时间:2017-07-08 21:18:42

标签: php html arrays laravel blade

这是我真正应该做的事情。但我出于某种原因无法让它发挥作用。

在我的控制器中,我有这样的代码

$challenges = \DB::table('challenges')->get();
echo print_r($challenges);
return view('challenge.ViewChallenges.ChallengeList',compact('challenges'));

echo将数据库中的2行打印到页面上,如此

Illuminate\Support\Collection Object ( [items:protected] => Array ( [0] => stdClass Object ( [id] => 1 [Name] => ian [Description] => desc1 [StartDate] => 2017-07-07 [SubmissionDate] => 2017-07-14 [Active] => 1 [Requirements] => qwerty [SubmissionCap] => 3 [DataUsage] => 4 [created_at] => 2017-07-08 20:00:08 [updated_at] => 2017-07-08 20:00:08 ) [1] => stdClass Object ( [id] => 2 [Name] => ggggggggggggg [Description] => dfsdfs [StartDate] => 2017-07-21 [SubmissionDate] => 2017-07-28 [Active] => 1 [Requirements] => req sum [SubmissionCap] => 56 [DataUsage] => 78 [created_at] => 2017-07-08 20:00:36 [updated_at] => 2017-07-08 20:00:36 ) ) ) 1

在我看来,我可以使用此

遍历每个条目
@foreach($challenges as $challenge)
   @foreach($challenge as $item)
      {{$item}}
   @endforeach
@endforeach

我已经尝试过大量的东西,例如只是名字,但似乎我可能会忽略某些小东西。我在这里看过非常类似的问题,但它似乎没有解决我的问题。也许$ challenge不是真正的2 dim阵列?

0 个答案:

没有答案