I've look all around SO for similar questions and tried every answers. The validator checks the rules and redirects fine. But the $errors variable is still empty in my views.
Controller:
public function postSlidesAdd(Request $request)
{
$validator = Validator::make($request->all(), [
'priority' => 'required',
'text' => 'required',
'image' => 'required'
]);
if ($validator->fails()) {
return redirect()->back()->withErrors($validator);
}
//insert to db and redirect back
}
Routes:
Route::group(['middleware' => ['web']], function () {
Route::post('/admin/slides/add', [
'uses' => 'SitesController@postSlidesAdd',
'as' => 'admin.slides.add'
]);
});
View:
<div class="">
@if(count($errors)>0))
<ul>
@foreach($errors->all() as $error)
<li>{{$error}}</li>
@endforeach
</ul>
@endif
</div>
I think I'm missing something small and important, please help. I'm using Laravel 5.2.29
UPDATE: If this is of any help; In my controller:
if ($validator->fails()) {
dd($validator->errors());
return back()->withErrors($validator);
}
This dumps an array 'messages' and inside is another array containing [input names => error messages]. I think this is the array to be sent to the views, but it doesn't get through. Help please what Am I doin wrong.
$validator->message()?messages()