我坚持使用默认的Laravel Auth。我通过php artisan make:auth
生成了它。
我的用户表需要的字段多于默认提供的字段。这是我对表的迁移。
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');
}
}
然后,我编辑了User.php
模型并更新了$fillable
字段。
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',
];
}
当我提交表单时,它会正确发布到数据库并存储。我可以看到这一行。
问题是,现在当我在创建新用户后注销并返回登录并填写表单时,它会返回错误,指出我输入的电子邮件地址与任何记录都不匹配,即使数据库中显然有一行具有相同的数据和相同的列名。
我做错了什么?
@The Alpha 在评论中的回答解决了我的问题。
我的过程是正确的,除了我没有考虑到密码是散列的,并且我的数据库字段中没有足够的字符可用于散列。
$table->string('password', 20);
需要更改为$table->string('password', 60);