5

I basically wan't to create a table based on all my model's attributes with Laravel, but the problem is, that the getAttributes() method ignores my custom added accessors even though I've added the name of the property to the $appends property (which adds it to json and array convertions). But still, I can't get my custom property. Any ideas?

0

1 Answer 1

8

You can access to all model attributes (including the Model::$appends attributes) by calling the Model::attributesToArray() method. Here is an example.

$modelAttributes = $model->attributesToArray();

$modelAttributeNames = array_keys($modelAttributes);
Sign up to request clarification or add additional context in comments.

2 Comments

Nice and very useful
Laravel 10.x in 2024... anyone care to suggest why $model->getAttributes() ignores the model casts?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.