Reputation: 622
I am trying to learn Laveral 5.2 and have the following in my routes.php:
Route::group(['middleware' => ['web'] ], function() {
Route::get('/', function () {
return view('welcome'); });
Route::post('/signup', [ 'uses' =>'UserController@postSignUp',
'as' => 'signup']);
Route::post('/signin', [ 'uses' => 'UserController@postSignIn',
'as' => 'signin']);
Route::get('/dashboard',['uses' =>'UserController@getDashboard',
'as' => 'dashboard' ]);
});
In my Controller I have some validation:
$this->validate( $request, [
'email' => 'required|email|unique:users',
'first_name' =>'required|max:120',
'password' => 'required|min:4'
]);
and in my logon screen I have the following:
@if (count($errors) > 0 )
<div class="row">
<div class="col-md-12">
<ul>
@foreach($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
</div>
The error array seems to always be empty.
Upvotes: 1
Views: 298
Reputation: 163778
Try to remove web middleware if you're using Laravel 5.2.27 and higher. web
middleware is adding automatically now to all routes and if you're trying to add it manually, it causes problems similar to yours.
It already helped many people to solve similar problems. I hope it'll help you too.
Upvotes: 1
Reputation: 7105
Try this
$validator = Validator::make($request->all(), [
'email' => 'required|email|unique:users',
'first_name' =>'required|max:120',
'password' => 'required|min:4'
]);
if ($validator->fails()) {
return view('your_view_name')->withErrors($validator)->with(['val1' => $val1,......]);
}
Upvotes: 0