Reputation:
I have this code in my controller:
public function contact(){
$people = ['Michael', 'martin', 'Peter', 'Marian'];
return view('contact', compact('people'));
}
and in my contact.blade.php:
@extends('layouts.app')
@section('content')
<h1>Contact Page</h1>
@if (count($people))
<ul>
@foreach(@people as $person)
<li>{{$person}}</li>
@endforeach
</ul>
@endif
@endsection
@section('footer')
@endsection
I am getting the error: Invalid argument supplied for foreach() (View: /home/mao/Documents/blog/resources/views/contact.blade.php)
I do not see the error.. been rewriting it twice. this should be correct as far as i can see on online guides?
Upvotes: 0
Views: 82
Reputation: 144
change @people to $people (@ => $)
@extends('layouts.app')
@section('content')
<h1>Contact Page</h1>
@if (count($people))
<ul>
@foreach($people as $person)
<li>{{$person}}</li>
@endforeach
</ul>
@endif
@endsection
@section('footer')
@endsection
Upvotes: 0
Reputation: 580
I think you just have a mistype in your foreach
Try this
@foreach($people as $person)
<li>{{$person}}</li>
@endforeach
Change the @
in $
Upvotes: 2