Download the PHP package jn-jairo/laravel-eloquent-cast without Composer
On this page you can find all versions of the php package jn-jairo/laravel-eloquent-cast. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jn-jairo/laravel-eloquent-cast
More information about jn-jairo/laravel-eloquent-cast
Files in jn-jairo/laravel-eloquent-cast
Package laravel-eloquent-cast
Short Description Cast for Laravel Eloquent.
License MIT
Homepage https://github.com/jn-jairo/laravel-eloquent-cast
Informations about the package laravel-eloquent-cast
Cast for Laravel Eloquent
This package extends the built-in attribute casting with the jn-jairo/laravel-cast package.
Version Compatibility
Laravel | Eloquent Cast |
---|---|
5.8.x | 1.x |
6.x | 1.x |
7.x | 2.x |
8.x | 3.x |
9.x | 3.x |
10.x | 3.x |
11.x | 3.x |
12.x | 3.x |
Installation
You can install the package via composer:
Usage
Use the trait \JnJairo\Laravel\EloquentCast\HasAttributesCast
in a \Illuminate\Database\Eloquent\Model
.
In the $casts
property of the model set the attribute name as the key and the type:format as the value.
The attribute is casted for a PHP
type in the getter and/or with a suffix, for a database
type in the setter, and for a json
type when serialized to array
/json
.
Example
Configuration
Publish the configuration to config/eloquent-cast.php
.
In the default configuration the attribute is casted for a PHP
type in the getter and with the _
suffix, except for the type uuid
which is casted only with the _
suffix,
because to cast a primary/foreign key directly in the getter brakes the relations between the eloquent models.
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-eloquent-cast with dependencies
illuminate/support Version ^8.83|^9.0|^10.0|^11.0|^12.0
jn-jairo/laravel-cast Version ^2.0.2