PHPackages                             sfneal/casts - 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. sfneal/casts

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

sfneal/casts
============

An alternative implementation of the Eloquent Model accessors &amp; mutators pattern for type casting attributes

2.0.0(2y ago)060.2k[2 PRs](https://github.com/sfneal/casts/pulls)1MITPHPPHP ^8.0|^8.1|^8.2|^8.3CI passing

Since Aug 14Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/sfneal/casts)[ Packagist](https://packagist.org/packages/sfneal/casts)[ Docs](https://github.com/sfneal/casts)[ RSS](/packages/sfneal-casts/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (10)Dependencies (6)Versions (17)Used By (1)

Casts
=====

[](#casts)

[![Packagist PHP support](https://camo.githubusercontent.com/60a8981d894122d996c9175346f34a6979aea5099cfd1571525b0f7aa0219812/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f73666e65616c2f6361737473)](https://packagist.org/packages/sfneal/casts)[![Latest Version on Packagist](https://camo.githubusercontent.com/03ca65e76f6cf611d0a62f8c6b27cc69a32549bb3eb24718fecb7a2e76ea43f5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73666e65616c2f63617374732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sfneal/casts)[![Build Status](https://camo.githubusercontent.com/afe216d69653b85c4b5374ac7b72758a6b64a8c01a375fb8fd577acd0f0a6123/68747470733a2f2f7472617669732d63692e636f6d2f73666e65616c2f63617374732e7376673f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://travis-ci.com/sfneal/casts)[![StyleCI](https://camo.githubusercontent.com/c364a9f197a2c303aef21e75c9b8146118e884191279155170dffdf31287bc18/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3238373535343337352f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/287554375?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/883460238a73a586a1186e1cdd5816162b296c9e2b75a46650d25ad5dd07c787/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f73666e65616c2f63617374732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/sfneal/casts/?branch=master)[![Total Downloads](https://camo.githubusercontent.com/6c363bd15c8ede819c1d0eb04967bc3a95850771037a072b620088079d3fa94c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73666e65616c2f63617374732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sfneal/casts)

An alternative implementation of the Eloquent Model accessors &amp; mutators pattern for type casting attributes

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require sfneal/casts
```

Usage
-----

[](#usage)

In order to make use of the attribute type Casts add the `HasCustomCasts` trait to your model before definition attributes that should be cast to custom types.

```
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Sfneal\Casts\CarbonCast;
use Sfneal\Casts\NewlineCast;
use Sfneal\Casts\NullableIntArrayCast;
use Sfneal\LaravelCustomCasts\HasCustomCasts;

class People extends Model
{
    use HasCustomCasts;

    protected $table = 'people';
    protected $primaryKey = 'person_id';

    protected $fillable = [
        'person_id',
        'name_first',
        'name_last',
        'email',
        'birthday',
        'bio',
        'favorites',
    ];

    /**
     * @var array Attributes that should be type cast
     */
    protected $casts = [
        'birthday' => CarbonCast::class,
        'bio' => NewlineCast::class,
        'favorites' => NullableIntArrayCast::class,
    ];
}
```

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Stephen Neal](https://github.com/sfneal)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

PHP Package Boilerplate
-----------------------

[](#php-package-boilerplate)

This package was generated using the [PHP Package Boilerplate](https://laravelpackageboilerplate.com).

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance52

Moderate activity, may be stable

Popularity23

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 97.1% 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 ~103 days

Recently: every ~292 days

Total

14

Last Release

762d ago

Major Versions

0.5.0 → 1.0.02021-02-01

1.2.0 → 2.0.02024-04-16

PHP version history (6 changes)0.1.0PHP ^7.1

0.2.0PHP ^7.0

0.2.2PHP &gt;=7.0

0.4.0PHP &gt;=7.1

0.5.0PHP &gt;=7.3

2.0.0PHP ^8.0|^8.1|^8.2|^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/ec5fdf3b9d2183ae9c777e4aed46fd5cfd9aa4789cd05c669e5907de0b8c865c?d=identicon)[sfneal](/maintainers/sfneal)

---

Top Contributors

[![sfneal](https://avatars.githubusercontent.com/u/23200215?v=4)](https://github.com/sfneal "sfneal (68 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")

---

Tags

castssfneal

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sfneal-casts/health.svg)

```
[![Health](https://phpackages.com/badges/sfneal-casts/health.svg)](https://phpackages.com/packages/sfneal-casts)
```

###  Alternatives

[wendelladriel/laravel-lift

Take your Eloquent Models to the next level

70046.8k](/packages/wendelladriel-laravel-lift)[vkovic/laravel-custom-casts

Make your own custom cast type for Laravel model attributes

218362.7k3](/packages/vkovic-laravel-custom-casts)[jerome/filterable

Streamline dynamic Eloquent query filtering with seamless API request integration and advanced caching strategies.

19226.1k](/packages/jerome-filterable)[hyperf/database

A flexible database library.

202.8M257](/packages/hyperf-database)[alajusticia/laravel-expirable

Make Eloquent models expirable

2193.4k5](/packages/alajusticia-laravel-expirable)[renoki-co/laravel-useful-casts

Laravel Useful Casts is a simple package for Laravel 7.0+ that comes with already-tested and already-written, useful casts for Eloquent models.

103.6k1](/packages/renoki-co-laravel-useful-casts)

PHPackages © 2026

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