Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve fillable fields in Laravel

In laravel 5.4, I'm able to retrieve fillable fields by using fillable index of model instance.

$model = new AnyClass();
dd($model['fillable']);

The above code prints all fillable fields of AnyClass. But the same code prints null on laravel 5.6. I know I can retrieve fillable fields using $model->getFillable(). My question is what is the reason / why it is not working in laravel 5.6 but works in 5.4?

like image 538
Vidhyut Pandya Avatar asked Feb 28 '19 12:02

Vidhyut Pandya


1 Answers

From the upgrade guide here I believe this is the answer to the question:

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 the data_get helper function.

like image 100
nakov Avatar answered Sep 19 '22 17:09

nakov