Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

larafam's avatar

$append vs api resource

whats the differences between them? im building spa and most of the extra attribute are attached inside api resource class, can some one clarify this for me?

0 likes
4 replies
tykus's avatar

The model's $append property defines an array of computed properties derived from Accessor methods which will be appended the to Array Representation of a Model instance.

An Eloquent API Resource allows you to structure and format a Model instance and it's loaded relations as a JSON API response.

Generally, I would suggest an API response if your project is non-trivial; you don't want your API changing everytime a column is added/removed from a database table.

2 likes
larafam's avatar

so basically its the same thing right? append will appear as json representation if im not using api resource

tykus's avatar

Essentially, you will get the same API response payload, yes.

Whenever you start using the $hidden Model property to hide properties from Array Representation of a Model, it is past time to look at an alternative approach.

You can override the toArray method on the Model class as well to define the array/JSON structure and format, but again I would tend towards API Resources in those cases.

1 like

Please or to participate in this conversation.