Download the PHP package cangelis/data-models without Composer
On this page you can find all versions of the php package cangelis/data-models. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package data-models
Data models
Data models is the beautiful way of working with structured data such as JSON, XML and php arrays. They are basically wrapper classes to the JSON and XML strings or php arrays. Models simplify the manipulation and processing workflow of the JSON, XML or php arrays.
Pros
- Straightforward to get started (this page will tell you all the features)
- Avoid undefined index by design
- Dynamic access to the model properties so no need of mapping the class properties with JSON or XML attributes
- IDE auto-completion using
@property
docblock and make the API usage documented by default - Has many and has one relationships between models
- Ability to assign default values for the attributes so the undefined attributes can be handled reliably
- Ability to add logic into the data in the model
- Cast values to known types such as integer, string, float, boolean
- Cast values to Carbon object to work on date attributes easily
- Ability to implement custom cast types
- Manipulate and work on the object models instead of arrays and make them array or serialize to JSON back
Install
composer require cangelis/data-models:^2.0
JSON Usage
Imagine you have a JSON data for a blog post looks like this
You can create the models looks like this
Use the models
XML Usage
It is pretty straightforward and very similar to JSON models.
Imagine an XML data:
You can setup a relationship looks like this:
Once you setup the relationships and your data, you start using the data.
The resulting XML will be;
Available Casts
Here are the available casts.
Custom Casts
If you prefer to implement more complex value casting logic, data models allow you to implement your custom ones.
Imagine you use Laravel Eloquent and want to cast an in a JSON attribute.
Contribution
Feel free to contribute!