Advanced Usage
Eloquent Casting
Use Laravel Data objects as Eloquent casts for seamless model integration
Since data objects can be created from arrays and easily transformed back to arrays, they work excellently with Eloquent casts.
Store a data object in a model:
Or use an array representation:
Retrieve the data object:
Cast to an abstract data class:
Store either child type:
Create with data objects or arrays:
Define default values in the data class:
Data is encrypted when stored and decrypted when retrieved automatically.
⌘I