Download the PHP package zero-to-prod/data-model-helper without Composer
On this page you can find all versions of the php package zero-to-prod/data-model-helper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download zero-to-prod/data-model-helper
More information about zero-to-prod/data-model-helper
Files in zero-to-prod/data-model-helper
Package data-model-helper
Short Description Helpers for a DataModel.
License MIT
Homepage https://github.com/zero-to-prod/data-model-helper
Informations about the package data-model-helper
Zerotoprod\DataModelHelper
Utilities for casting values using the DataModel package.
Installation
Install the package via Composer:
Additional Packages
- DataModel: Transform data into a class.
- DataModelFactory: A factory helper to set the value of your
DataModel
. - Transformable: Transform a
DataModel
into different types.
Quick Start
Here’s how to use the mapOf
helper with all its arguments:
Usage
Including the Trait
Include the DataModelHelper
trait in your class to access helper methods:
mapOf()
The mapOf()
method returns an array of Alias
instances.
Laravel Collection Example
The mapOf
helper is designed to work will with the \Illuminate\Support\Collection
class.
Coercing
Sometimes, an attribute may contain either a single element or an array of elements. By setting 'coerce' => true
, you can ensure that single
elements
are coerced into an array.
Using a Custom Mapping Function
Specify your mapping function by setting the using
option.
Specifying a Custom Mapping Method
By default, the map method is used to map over elements. You can specify a different method using the map_via
option.
Deep Mapping
You can set the level for mapping deep arrays.