Skip to content

Commit 4e75a35

Browse files
authored
Merge pull request #6123 from laravel/note-serializing-value-objects
[7.x] Note about serializing value objects
2 parents 6026b3a + c8c42ee commit 4e75a35

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

eloquent-mutators.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ When casting to value objects, any changes made to the value object will automat
316316

317317
$user->save();
318318

319+
> {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.
320+
319321
#### Inbound Casting
320322

321323
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.

0 commit comments

Comments
 (0)