I am trying to get validation errors to display in my application and have run into a wall.
I have tried this a few different ways, this is how I have it setup currently...
My routes look like this:
<?php
Route::group(['middleware' => ['web']], function () {
Route::get('/', [
'as' => 'home',
'uses' => 'HomeController@index'
]);
Route::post('/mailing', [
'as' => 'mailing.create',
'uses' => 'MailingController@create'
]);
});
My mailing controller looks like this:
class MailingController extends Controller
{
public function create(Request $request)
{
$this->validate($request, [
'email' => 'required',
]);
dd($request->email);
}
}
My form looks like this...
<form action="{{ route('mailing.create') }}" method="post">
<label for="email">
Email
<input type="text" name="email" id="email">
@if ($errors->has('email'))
{{ $errors->first('email') }}
@endif
</label>
<input type="submit">
{{ csrf_field() }}
</form>
When I submit an empty form it goes to the create method in the MailingController however nothing happens, no errors are displayed. Just the form.
Really this should work, could the issue possibly be that the example above was good for Laravel 5.1 but does not work in the latest 5.2 version?
Many thanks in advance for your kind consideration.