1

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.

Jim
  • 596
  • 1
  • 10
  • 36
  • can you post the controller method ? also you are not closing `@endif` – Gntem May 07 '16 at 12:02
  • The endif is there I just missed copying it. Here is the controller method: public function postSignUp(Request $request) { $this->validate( $request, [ 'email' => 'required|email|unique:users', 'first_name' =>'required|max:120', 'password' => 'required|min:4' ]); $email = $request['email']; $first_name = $request['first_name']; $password = bcrypt($request['password']); $user = new User(); $user->email = $email; $user->first_name = $first_name; $user->password = $password; $user->save(); Auth::login($user); } – Jim May 07 '16 at 12:15

2 Answers2

1

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.

Community
  • 1
  • 1
Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279
0

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,......]);
        }
paranoid
  • 6,799
  • 19
  • 49
  • 86