Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Laravel(php)中将数组传递给视图_Php_Laravel - Fatal编程技术网

在Laravel(php)中将数组传递给视图

在Laravel(php)中将数组传递给视图,php,laravel,Php,Laravel,我正在尝试将一个数组传递到Laravel中的blade view。 以下是我在控制器中的代码: $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', '%' . $c

我正在尝试将一个数组传递到Laravel中的blade view。 以下是我在控制器中的代码:

$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为字符串,数组给定


有人能帮忙吗?

你必须这样做

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

您在这里所做的与使用
echo
回送数组相同,因此您需要根据需要更新代码

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

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

考虑到这一点

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

就像@Narendra Sisodia在@event_nav中说的那样,我只想选择访问日期的年份。。那么,我怎样才能做到这一点呢?{{$year->Visit_Date}不工作->选择(DB::raw('year(Visit_Date)作为Visit_Date'))谢谢-我会更改它。谢谢-我会更改它。
@foreach($event_nav as $year)
   {{$year->Visit_Date}}
@endforeach