Reputation: 131
I am trying to pass an array to blade view in Laravel. Here is my code in controller:
$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'));
and here is my view:
@foreach($event_nav as $year)
{{$event_nav[0]}}
@endforeach
I'm getting following error message :
"htmlentities() expects parameter 1 to be string, array given"
can anyone help?
Upvotes: 1
Views: 766
Reputation: 3784
replace
->select(DB::raw('YEAR(Visit_Date)'))
with
->select(DB::raw('YEAR(Visit_Date) AS Visit_Date'))
and in view do this
@foreach($event_nav as $year)
{{$year->Visit_Date}}
@endforeach
like @Narendra Sisodia said
Upvotes: 0
Reputation: 21422
What you were doing over here is same as echoing an array using echo
so you need to update your code as
@foreach($event_nav as $year)
{{$year->Visit_Date}}
@endforeach
Upvotes: 1
Reputation: 2787
you have to do something like this
@foreach($event_nav[0] as $year)
{{$year->Child_ID}}
{{$year->blah}}
@endforeach
Upvotes: 1