doucong3048 2016-02-06 00:36
浏览 43
已采纳

Laravel身份验证

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条回答 默认 最新

  • duanjunao9348 2016-02-06 02:28
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题