A data object can automatically be transformed into an array:Documentation Index
Fetch the complete documentation index at: https://mintlify.com/spatie/laravel-data/llms.txt
Use this file to discover all available pages before exploring further.
By default,
toArray recursively transforms all properties. Nested data objects, collections, and complex types like Carbon, DateTime, Enums will be transformed.Without Transforming Properties
If you only want to transform a data object to an array without transforming the properties:To JSON
You can also manually transform a data object to JSON:Using Collections
Create a collection of data objects:Nesting Data Objects
You can nest data objects within other data objects:Nesting Collections
You can also nest a collection of data objects:Hiding properties
You can hide specific properties from being included in the transformation using theHidden attribute:
password property will never be included when transforming the data object to an array or JSON:
The
Hidden attribute is useful for excluding sensitive data like passwords, API tokens, or internal properties from API responses.