gpt4 book ai didi

php - 添加字段注册页面 Laravel 5.4

转载 作者:行者123 更新时间:2023-12-03 20:37:21 26 4
gpt4 key购买 nike

我想使用 Laravel Auth 在我的注册页面上添加一个字段。基本用户表包含姓名、电子邮件、密码。我想添加一个正确的字段。

所以我将 create_users_table.php 迁移文件编辑为

public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->integer('right_id');
$table->rememberToken();
$table->timestamps();
});
}

和我的registercontroller.php

protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'right_id' => 0,
'password' => bcrypt($data['password']),
]);
}

但它不起作用。我仍然有关于 right_id 的错误。似乎该值未发送到数据库。

任何修复/帮助?谢谢

最佳答案

您是否像下面的代码示例那样在 User 模型类中指定了您的 right_id?如果您忘记在 $fillable 中声明附加字段,该值将不会保存到数据库中。

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password', 'right_id'
];
}

关于php - 添加字段注册页面 Laravel 5.4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42335001/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com