Skip to content

Commit

Permalink
Merge pull request #6123 from laravel/note-serializing-value-objects
Browse files Browse the repository at this point in the history
[7.x] Note about serializing value objects
  • Loading branch information
taylorotwell authored Jun 18, 2020
2 parents 6026b3a + c8c42ee commit 4e75a35
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions eloquent-mutators.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ When casting to value objects, any changes made to the value object will automat

$user->save();

> {tip} If you plan to serialize your Eloquent models containing value objects to JSON or arrays, you should implement the `Illuminate\Contracts\Support\Arrayable` and `JsonSerializable` interfaces on the value object.
#### Inbound Casting

Occasionally, you may need to write a custom cast that only transforms values that are being set on the model and does not perform any operations when attributes are being retrieved from the model. A classic example of an inbound only cast is a "hashing" cast. Inbound only custom casts should implement the `CastsInboundAttributes` interface, which only requires a `set` method to be defined.
Expand Down

0 comments on commit 4e75a35

Please sign in to comment.