PHPackages                             grummfy/eloquent-extended-cast-model - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. grummfy/eloquent-extended-cast-model

ActiveLibrary[Database &amp; ORM](/categories/database)

grummfy/eloquent-extended-cast-model
====================================

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

1.0.2(7y ago)5191[1 issues](https://github.com/Grummfy/eloquent-extended-cast-model/issues)MITPHP

Since Jan 28Pushed 7y ago1 watchersCompare

[ Source](https://github.com/Grummfy/eloquent-extended-cast-model)[ Packagist](https://packagist.org/packages/grummfy/eloquent-extended-cast-model)[ RSS](/packages/grummfy-eloquent-extended-cast-model/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (4)Used By (0)

Laravel extended cast model
===========================

[](#laravel-extended-cast-model)

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

Compatible with laravel 5.4 and upper.

Tested with laravel 5.4, 5.5, 5.6 and 5.7.

Install
-------

[](#install)

```
composer require grummfy/eloquent-extended-cast-model

```

Usage
-----

[](#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

See [example](example) directory for a possible usage.

### Custom casting in your model

[](#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']`.

### Cast JsonReadOnlyCollection

[](#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.

TODO
----

[](#todo)

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

Note
----

[](#note)

The basic idea was inspired from

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~152 days

Total

3

Last Release

2721d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/668804?v=4)[Grummfy](/maintainers/Grummfy)[@Grummfy](https://github.com/Grummfy)

---

Top Contributors

[![Grummfy](https://avatars.githubusercontent.com/u/668804?v=4)](https://github.com/Grummfy "Grummfy (6 commits)")

---

Tags

casteloquentlaraveltraitlaraveleloquenttraitscast

### Embed Badge

![Health badge](/badges/grummfy-eloquent-extended-cast-model/health.svg)

```
[![Health](https://phpackages.com/badges/grummfy-eloquent-extended-cast-model/health.svg)](https://phpackages.com/packages/grummfy-eloquent-extended-cast-model)
```

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11320.2M21](/packages/anourvalar-eloquent-serialize)[bavix/laravel-clickhouse

Eloquent model for ClickHouse

72214.1k2](/packages/bavix-laravel-clickhouse)[io238/laravel-iso-countries

Ready-to-use Laravel models and relations for country (ISO 3166), language (ISO 639-1), and currency (ISO 4217) information with multi-language support.

5462.3k](/packages/io238-laravel-iso-countries)[rennokki/eloquent-settings

Eloquent Settings allows you to bind key-value pairs to any Laravel Eloquent model. It supports even casting for boolean, float or integer types.

804.2k](/packages/rennokki-eloquent-settings)[stayallive/laravel-eloquent-observable

Register Eloquent model event listeners just-in-time directly from the model.

2928.9k7](/packages/stayallive-laravel-eloquent-observable)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
