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.

2
  • can you post the controller method ? also you are not closing @endif Commented May 7, 2016 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); } Commented May 7, 2016 at 12:15

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks so much. That's it. All OK now!
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,......]);
        }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.