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 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)