This is the documentation for
v2 but the latest version is
You can switch versions in the menu on the left/at the top.
Check your current version with the following command:
composer show spatie/laravel-data
Casts take simple values and cast them into complex types. For example,
16-05-1994T00:00:00+00 could be cast into a
Carbon object with the same date.
A cast implements the following interface:
public function cast(DataProperty $property, mixed $value, array $context): mixed;
The value that should be cast is given, and a
DataProperty object which represents the property for which the value is cast. You can read more about the internal structures of the package here.
context array the complete payload is given.
In the end, the cast should return a casted value. Please note that the given value of a cast can never be
When the cast is unable to cast the value, an
Uncastable object should be returned.