Skip to content

Commit

Permalink
[10.x] update note about appending accessors (laravel#8585)
Browse files Browse the repository at this point in the history
* update note about appending accessors

the current wording makes it seem like you have to add the attribute to the `$appends` property.  I'm hoping this new wording emphasizes that it is optional, and helps the reader understand when and why they would or would not want to use it.

* Update eloquent-serialization.md

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
browner12 and taylorotwell authored Feb 16, 2023
1 parent 9f68d70 commit 9e8b81a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion eloquent-serialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Occasionally, when converting models to arrays or JSON, you may wish to add attr
}
}

After creating the accessor, add the attribute name to the `appends` property of your model. Note that attribute names are typically referenced using their "snake case" serialized representation, even though the accessor's PHP method is defined using "camel case":
If you would like the accessor to always be appended to your model's array and JSON representations, you may add the attribute name to the `appends` property of your model. Note that attribute names are typically referenced using their "snake case" serialized representation, even though the accessor's PHP method is defined using "camel case":

<?php

Expand Down

0 comments on commit 9e8b81a

Please sign in to comment.