尝试使用 Laravel 中的自定义字段“user_id”登录

我正在尝试使用名为“user_id”的自定义字段登录,但它不起作用。我收到页面过期错误。请帮忙。


登录页面


<form role="form" action=" {{route('user.login')}}" method="POST">

                <div class="form-group mb-3">

                  <div class="input-group input-group-alternative">

                    <div class="input-group-prepend">

                      <span class="input-group-text"><i class="ni ni-email-83"></i></span>

                    </div>

                    <input class="form-control" placeholder="User Id" name="user_id" type="text">

                  </div>

                </div>

                <div class="form-group">

                  <div class="input-group input-group-alternative">

                    <div class="input-group-prepend">

                      <span class="input-group-text"><i class="ni ni-lock-circle-open"></i></span>

                    </div>

                    <input class="form-control" placeholder="Password" name="password" type="password">

                  </div>

                </div>

                <div class="text-center">

                  <button type="submit" class="btn btn-primary my-4">Log in</button>

                </div>

              </form>

我的数据库字段 id user_id user_name password type role remember_token created_at updated_at


顺便说一下,我的 remember_token id null 总是我不知道为什么。


在 Illuminate\Foundation\Auth\AuthenticatesUsers 中更改


public function username()

    {

        return 'user_id';

    }

网页.php


Route::get('/login', 'UserController@login_form')->name('user.loin_form');

Route::post('/login', 'Auth\LoginController@login')->name('user.login');

我错过了什么


料青山看我应如是
浏览 152回答 1
1回答

小怪兽爱吃肉

只需将其添加csrf token到您的表单中,它就会起作用。您可以添加@csrf刀片指令或手动创建您的 csrf 输入,如下所示:<input type="hidden" name="_token" value="{{ csrf_token() }}">使用刀片指令:<form role="form" action=" {{route('user.login')}}" method="POST">&nbsp; &nbsp; @csrf&nbsp; &nbsp; <div class="form-group mb-3">&nbsp; &nbsp; &nbsp; &nbsp; <div class="input-group input-group-alternative">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="input-group-prepend">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="input-group-text"><i class="ni ni-email-83"></i></span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input class="form-control" placeholder="User Id" name="user_id" type="text">&nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; </div>&nbsp; &nbsp; <div class="form-group">&nbsp; &nbsp; &nbsp; &nbsp; <div class="input-group input-group-alternative">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="input-group-prepend">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="input-group-text"><i class="ni ni-lock-circle-open"></i></span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <input class="form-control" placeholder="Password" name="password" type="password">&nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; </div><div class="text-center">&nbsp; &nbsp; <button type="submit" class="btn btn-primary my-4">Log in</button></div></form>希望能帮助到你。
打开App,查看更多内容
随时随地看视频慕课网APP