尝试插入数据时收到此错误消息将 [name] 添加到可填充 属性 以允许对 [App\Suitspecialist] 进行批量分配

When trying to insert data got this error msg Add [name] to fillable property to allow mass assignment on [App\Suitspecialist]

任何人都可以向我解释为什么控制器部分抛出错误吗?

这是我的模型:

class Suitspecialist extends Authenticatable
{
    use Notifiable;
    protected $guard = 'suitspecialist';
    protected $fillable = [
        'name', 'email', 'password',
    ];
    protected $hidden = [
        'password', 'remember_token',
    ];
}

控制器

这部分会引发错误

将 [name] 添加到可填写的 属性 以允许对 [App\Suitspecialist] 进行批量分配。

protected function createSuitspecialist(Request $request)
{
    $this->validator($request->all())->validate();
    Suitspecialist::create([
        'name' => $request->name,
        'email' => $request->email,
        'password' => Hash::make($request->password),
    ]);
    return redirect()->intended('login/suitspecialist');
}

您不能同时使用 guardedfillable。最好只使用 fillable.

当您尝试使用填充、创建或更新等方法在模型上填充多个属性时,您需要指定可以通过这种方式填充的字段。这是调用 "mass assignment"。

这是一项 Eloquent 安全措施,旨在避免您存储不想存储的数据。

在您的模型中,使用 guardedfillable 属性来指定您想要或不想注册的属性使用批量赋值。这些属性接受一个数组。

查看 Laravel 文档,它有很好的解释:https://laravel.com/docs/7.x/eloquent#mass-assignment