在 laravel 5.4 中,我可以通过使用模型实例的 fillable
索引来检索可填写的字段。
$model = new AnyClass();
dd($model['fillable']);
上面的代码打印了 AnyClass
的所有可填写字段。但是相同的代码在 laravel 5.6 上打印出 null
。我知道我可以使用 $model->getFillable()
检索可填写字段。我的问题是它在 laravel 5.6 中不起作用但在 5.4 中起作用的原因是什么?
最佳答案
来自升级指南here我相信这是问题的答案:
Model Methods & Attribute Names
To prevent accessing a model's private properties when using array access, it's no longer possible to have a model method with the same name as an attribute or property. Doing so will cause exceptions to be thrown when accessing the model's attributes via array access (
$user['name']
) or thedata_get
helper function.
关于php - 在 Laravel 中检索可填写字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54926270/