首先,您应该company
使用中找到的迁移将该字段添加到用户表中database\migrations\2014_10_12_000000_create_users_table.php
。
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('company');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->foreignId('current_team_id')->nullable();
$table->text('profile_photo_path')->nullable();
$table->timestamps();
});
}
然后运行此命令php artisan migrate:fresh
以迁移您的新用户表。
然后将该字段添加到User
模型中的可填充数组中,\app\Models\User.php
如下所示:
protected $fillable = [
'name',
'company',
'email',
'password',
];
现在您可以在下面找到注册视图,resources\views\auth\register.blade.php
然后您可以复制一个输入块以将其用于该'company'
字段。
然后你可以在这个类中进行验证:app\Actions\Fortify\CreateNewUser.php
public function create(array $input)
{
Validator::make($input, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'company' => ['required', 'string', 'max:255'],
'password' => $this->passwordRules(),
])->validate();
return User::create([
'name' => $input['name'],
'email' => $input['email'],
'company' => $input['company'],
'password' => Hash::make($input['password']),
]);
}
然后,你准备好了。