duanliexi1052 2016-03-17 16:56
浏览 14
已采纳

Laravel默认身份验证 - 添加字段会破坏登录能力

I'm stuck with the default Laravel Auth. I generated it through php artisan make:auth.

My User table requires more fields than the default provides. Here is my migration for the table.

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('first', 20)->nullable();
            $table->string('last', 20)->nullable();
            $table->string('email', 50)->unique();
            $table->string('password', 20);
            $table->integer('userRoleId')->unsigned()->index();
            $table->integer('userGroupId')->unsigned()->index();
            $table->integer('companyId')->unsigned()->index();
            $table->rememberToken();
            $table->timestamps();
        });
    }

    public function down()
    {
        Schema::drop('users');
    }
}

I then edited the User.php Model and updated the $fillable fields.

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    protected $fillable = [
        'first', 'last', 'email', 'password', 'userRoleId', 'userGroupId', 'companyId',
    ];

    protected $hidden = [
        'password', 'remember_token',
    ];
}

When I submit the form it posts properly to the database and is stored. I can see the row.

The problem is that now when I logout after creating a new user and return to login and fill out the form, it returns with errors stating that the email address I entered does not match any records even though there clearly is a row with the same data and same column name in the database.

What am I doing wrong?

  • 写回答

1条回答 默认 最新

  • douli7841 2016-03-17 17:41
    关注

    @The Alpha's answer in the comments solved my problem.

    My process was correct except for the fact that I didn't take into account that the password is hashed and not enough characters were made available to the hash in my database field.

    $table->string('password', 20); needed to be changed to $table->string('password', 60);

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

报告相同问题?

悬赏问题

  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名