首先,您应该使用位于
database\migrations\2014_10_12_000000_create_users_table.php
中的迁移,在用户表中添加
company
字段。
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
来迁移您的新用户表。
然后在\app\Models\User.php
中找到User
模型,并将该字段添加到可填充数组中,如下所示:
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']),
]);
}
那么,你已经准备好了。
php artisan migrate:fresh
在生产环境下会给你一个警告。这是因为在运行此命令后,你的数据库表中的数据将会丢失。 - Arif I.border-gray-300 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 rounded-md shadow-sm w-full
- Meysam Zarei