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 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用