Skip to main content
Since data objects can be created from arrays and easily transformed back to arrays, they work excellently with Eloquent casts.

Basic Usage

Cast a model attribute to a data object:
Store a data object in a model:
Or use an array representation:
Retrieve the data object:

Abstract Data Objects

Use abstract parent data objects with multiple child implementations:
Cast to an abstract data class:
Store either child type:

Database Storage Format

Child data objects are stored with type information:

Abstract Data with Collections

Cast collections of abstract data objects:

Morph Maps

Prevent class name changes from breaking your application:

Casting Data Collections

Store collections of data objects:
Create with data objects or arrays:

Default Values for Null

Instantiate data objects with defaults when database value is null:
Define default values in the data class:

Nullable Collections

Always return a DataCollection even when null:

Encryption

Encrypt data objects and collections automatically:
Data is encrypted when stored and decrypted when retrieved automatically.