-2
I am trying to display all records of a table but have the following error: Undefined variable: messages (View: /Users/Henrique/Documents/Laravel Projects/blog/Resources/views/messages.blade.php)
my controller:
public function getMessages() {
$messages = \App\Message::all();
return view('messages')->with(['Messages' => $messages]);
//return view('messages',[ 'images' => $messages]);
}
my view:
@extends('layout.app')
@section('content')
<h1>Messages</h1>
@if(count($messages)>0)
@foreach($messages as $message)
<ul>
<li class="list-group-item">Name: {{$message->name}}</li>
<li class="list-group-item">Email: {{$message->email}}</li>
<li class="list-group-item">Message: {{$message->message}}</li>
</ul>
@endforeach
@endif
@endsection
@section('sidebar')
@endsection