简体   繁体   English

Laravel身份验证

[英]Laravel Authentication

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? 还有什么我想念的?

Make sure the $middleware[]; 确保$middleware[]; array in app/http/Kernel.php have the following middleware registered: app/http/Kernel.php已注册以下中间件:

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

Alternatively, you can try registering the routes of authentication under web middleware, such that: 或者,您可以尝试在web中间件下注册身份验证路由,例如:

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. 我希望它能奏效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM