【问题标题】:Add [username] to fillable property to allow mass assignment on [App/post]将 [username] 添加到可填充属性以允许在 [App/post] 上进行批量分配
【发布时间】:2020-05-02 11:53:26
【问题描述】:

我正在学习 Laravel 和 PHP,我正在尝试使用来自 Artisan 的 Tinker 在我的表格中添加一个帖子。

我收到这些我不明白的错误:

Illuminate/Database/Eloquent/MassAssignmentException with message 'Add [username] to fillable property to allow mass assignment on [App/post].'

在我的 Post.php 模型中,我有:

    protected $fillable = ['username', 'email', 'content'];

感谢您的帮助

【问题讨论】:

  • 假设你的插入已经成为可能。但是您可以尝试用protected $guarded = []; 代替protected $fillable = ['username', 'email', 'content']; 吗?让我知道出现的错误?

标签: php laravel


【解决方案1】:

尝试退出 tinker 并再次运行 php artisan tiker,tinker 在运行时不会跟踪更改。

【讨论】:

  • 是的,但我必须等待 5 分钟才能完成
猜你喜欢
  • 2019-05-16
  • 2021-08-24
  • 1970-01-01
  • 2020-07-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多