I'm trying to display all records in a table but it has 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