How can I display the validation message in the view that is being redirected in Laravel ?
Here is my function in a Controller
publi
Laravel 4
When the validation fails return back with the validation errors.
if($validator->fails()) {
return Redirect::back()->withErrors($validator);
}
You can catch the error on your view using
@if($errors->any())
{{ implode('', $errors->all(':message')) }}
@endif
UPDATE
To display error under each field you can do like this.
@if($errors->has('firstname'))
{{ $errors->first('firstname') }}
@endif
For better display style with css.
You can refer to the docs here.
UPDATE 2
To display all errors at once
@if($errors->any())
{!! implode('', $errors->all(':message')) !!}
@endif
To display error under each field.
@error('firstname')
{{ $message }}
@enderror