3
votes

Hello I am trying to do a basic authentication.

View

<!-- Simple login form -->
            {!! Form::open(array('url' => '/auth/login')) !!}

                <div class="panel panel-body login-form">
                    <div class="text-center">
                        <div class="icon-object border-slate-300 text-slate-300"><i class="icon-reading"></i></div>
                        <h5 class="content-group">Login to your account <small class="display-block">Enter your credentials below</small></h5>
                    </div>
                    @if($errors->any())
                        <div class="alert alert-danger no-border">
                            The username or password you have entered is incorrect
                        </div>
                    @endif

                    <div class="form-group has-feedback has-feedback-left">
                        {{Form::text('username', null, array('class'=>'form-control', 'placeholder'=>'Username'))}}
                        <div class="form-control-feedback">
                            <i class="icon-user text-muted"></i>
                        </div>
                    </div>

                    <div class="form-group has-feedback has-feedback-left">
                        {{Form::password('password', array('class'=>'form-control', 'placeholder'=>'Password'))}}
                        <div class="form-control-feedback">
                            <i class="icon-lock2 text-muted"></i>
                        </div>
                    </div>

                    <div class="form-group">
                        <button type="submit" class="btn btn-primary btn-block">Sign in <i class="icon-circle-right2 position-right"></i></button>
                    </div>

                    <div class="text-center">
                        <a href="login_password_recover.html">Forgot password?</a>
                    </div>
                </div>
            {!! Form::close() !!}
            <!-- /simple login form -->

Routes


    Route::get('auth/login', 'Auth\AuthController@getLogin');
    Route::post('auth/login', 'Auth\AuthController@postLogin');
    Route::get('auth/logout', 'Auth\AuthController@getLogout');


    Route::get('auth/register', 'Auth\AuthController@getRegister');
    Route::post('auth/register', 'Auth\AuthController@postRegister')

;

But I am getting the following error

Undefined variable: errors

I didn't change anything else, I just want to do basic authentication. Please help me. What else did I miss?

1
Possible duplicate of Undefined variable: errors in Laravelsamrap
It's not a duplicate, that other question did not help me.Richard Tonata

1 Answers

1
votes

Make sure the $middleware[]; array in app/http/Kernel.php have the following middleware registered:

\Illuminate\View\Middleware\ShareErrorsFromSession::class,

Alternatively, you can try registering the routes of authentication under web middleware, such that:

Route::group(['middleware' => ['web']], function () {
    Route::get('auth/login', 'Auth\AuthController@getLogin');
    Route::post('auth/login', 'Auth\AuthController@postLogin');
    Route::get('auth/logout', 'Auth\AuthController@getLogout');

    Route::get('auth/register', 'Auth\AuthController@getRegister');
    Route::post('auth/register', 'Auth\AuthController@postRegister');
}

I hope it will work.