dpps0715 2019-07-14 00:37
浏览 189
已采纳

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

I am trying to login with a custom field called "user_id" but it is not working. I am getting page expired error. Please help.

Login page

<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>

My database fields id user_id user_name password type role remember_token created_at updated_at

by the way my remember_token id null always i don't know why.

changed in Illuminate\Foundation\Auth\AuthenticatesUsers

public function username()
    {
        return 'user_id';
    }

web.php

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

what did i missed

  • 写回答

1条回答 默认 最新

  • doupao2277 2019-07-14 01:36
    关注

    Just add the csrf token to your form and it will work.

    You can add the @csrf blade directive or manually create your csrf input, like this one:

    <input type="hidden" name="_token" value="{{ csrf_token() }}">
    

    Using the blade directive:

    <form role="form" action=" {{route('user.login')}}" method="POST">
        @csrf
        <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>
    

    Hope it helps.

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

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?