传递数组在Laravel(php)中查看

时间:2015-08-11 04:29:56

标签: php laravel

我正在尝试将数组传递给Laravel中的刀片视图。 这是我在控制器中的代码:

$event_nav= array();
       $event_nav[] = DB::table('tr_visit')
           ->join ('tm_child','tr_visit.Child_ID','=','tm_child.Child_ID')
           ->where('tr_visit.Child_ID', 'LIKE', '%' . $childName . '%')
           ->select(DB::raw('YEAR(Visit_Date)'))
           ->distinct()
           ->get();
 return view('ProfilAnak.BmiAnak.seeBmi',compact('event_nav'));

这是我的观点:

    @foreach($event_nav as $year)
       {{$event_nav[0]}}
    @endforeach

我收到以下错误消息:

  

“htmlentities()期望参数1为字符串,数组为”

任何人都可以帮忙吗?

3 个答案:

答案 0 :(得分:1)

你必须做这样的事情

@foreach($event_nav[0] as $year)
       {{$year->Child_ID}}
       {{$year->blah}}
@endforeach

答案 1 :(得分:1)

您在此处所做的与使用echo回显数组相同,因此您需要将代码更新为

@foreach($event_nav as $year)
   {{$year->Visit_Date}}
@endforeach

答案 2 :(得分:0)

替换

->select(DB::raw('YEAR(Visit_Date)'))

->select(DB::raw('YEAR(Visit_Date) AS Visit_Date'))

并在视野中执行此操作

@foreach($event_nav as $year)
   {{$year->Visit_Date}}
@endforeach
像@Narendra Sisodia说的那样