2017 © Pedro Peláez
 

library eloquent-extended-cast-model

This library help you to make more advanced cast to eloquent model.

image

grummfy/eloquent-extended-cast-model

This library help you to make more advanced cast to eloquent model.

  • Wednesday, February 14, 2018
  • by Grummfy
  • Repository
  • 1 Watchers
  • 5 Stars
  • 10 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Laravel extended cast model

This library help you to make more advanced cast to eloquent model., (*1)

Compatible with laravel 5.4 and upper., (*2)

Tested with laravel 5.4, 5.5, 5.6 and 5.7., (*3)

Install

composer require grummfy/eloquent-extended-cast-model

Usage

Using the trait to facilitate the usage of custom cast on model. There is two traits: * CastableModel: allow you to use custom cast * JsonCollectionCastable: allow you to use json collection on cast, (*4)

See example directory for a possible usage., (*5)

Custom casting in your model

  • add the trait CastableModel
  • in the $cast property of the model, add your field and the custom cast 'fooField' => 'bar'
  • add two methods: toBar and fromBar (Bar is the same name as the one present in the $cast property)

If you want to add some extra value to your cast method (like it's done in the JsonReadOnlyCollection), you can fill the property $castParameters of your model: 'fooField' => ['argument1', 'argument2']., (*6)

Cast JsonReadOnlyCollection

This library came with a json collection. It's a collection of value that are saved in json. It's nice to use with a collection of value object., (*7)

TODO

  • unit test
  • QA tools
    • travis
    • styleci
    • scrutinizer
    • ...

Note

The basic idea was inspired from https://github.com/reliese/laravel/blob/master/src/Database/Eloquent/Model.php, (*8)

The Versions

14/02 2018

dev-master

9999999-dev

This library help you to make more advanced cast to eloquent model.

  Sources   Download

MIT

The Requires

 

by Avatar Grummfy

laravel eloquent cast traits

14/02 2018

1.0.1

1.0.1.0

This library help you to make more advanced cast to eloquent model.

  Sources   Download

MIT

The Requires

 

by Avatar Grummfy

laravel eloquent cast traits

28/01 2018

1.0.0

1.0.0.0

This library help you to make more advanced cast to eloquent model.

  Sources   Download

MIT

The Requires

 

by Avatar Grummfy

laravel eloquent cast traits