PHPackages                             morningtrain/data-transfer-object-casters - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. morningtrain/data-transfer-object-casters

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

morningtrain/data-transfer-object-casters
=========================================

A package containing Data Transfer Object casters, for use with spatie/data-transfer-object

2.0.0(3y ago)42.8k1MITPHPPHP ^8.0

Since Nov 19Pushed 3y ago5 watchersCompare

[ Source](https://github.com/Morning-Train/data-transfer-object-casters)[ Packagist](https://packagist.org/packages/morningtrain/data-transfer-object-casters)[ Docs](https://github.com/morningtrain/data-transfer-object-casters)[ GitHub Sponsors](https://github.com/morningtrain)[ RSS](/packages/morningtrain-data-transfer-object-casters/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (2)Dependencies (9)Versions (8)Used By (0)

A package containing DTO casters
================================

[](#a-package-containing-dto-casters)

[![Latest Version on Packagist](https://camo.githubusercontent.com/c139c4d0a1e685b072997265a5d360f09a1a152966b94025ec0d7a5ae7b34e93/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6f726e696e67747261696e2f646174612d7472616e736665722d6f626a6563742d636173746572732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/morningtrain/data-transfer-object-casters)[![GitHub Tests Action Status](https://github.com/Morning-Train/data-transfer-object-casters/workflows/Tests/badge.svg)](https://github.com/Morning-Train/data-transfer-object-casters/workflows/Tests/badge.svg)[![Code style](https://camo.githubusercontent.com/d9194b1eaae54decf4def04b4314d42f0e309028afa52f3fad7d820f4e85c6d0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f4d6f726e696e672d547261696e2f646174612d7472616e736665722d6f626a6563742d636173746572732f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://github.com/SimonJnsson/data-transfer-object-casters/actions/workflows/php-cs-fixer.yml/badge.svg)[![Total Downloads](https://camo.githubusercontent.com/959cee268055d9144aa7b0fcb46abb82bbdf51cd168e0293f8a1ae00c960cee6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6f726e696e67747261696e2f646174612d7472616e736665722d6f626a6563742d636173746572732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/morningtrain/data-transfer-object-casters)

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

[](#installation)

You can install the package via composer:

```
composer require morningtrain/data-transfer-object-casters
```

Usage
-----

[](#usage)

To use the provided casters, add an attribute CastWith, to the property you want to cast.

```
class DTO extends DataTransferObject
{
    #[CastWith(BoolCaster::class)]
    public bool $bool;
}
```

### Bool

[](#bool)

The Boolean caster is used to cast the provided value to a boolean.

It uses FILTER\_VALIDATE\_BOOL, see the [php docs](https://www.php.net/manual/en/filter.filters.validate.php) for more information

### Date

[](#date)

The DateCaster will attempt to cast the provided value into a Carbon instance, using the provided format.

If no format is specified 'd.m.Y H:i:s' will be used.

```
use Morningtrain\DataTransferObjectCasters\Casters\DateCaster;

class DTO extends DataTransferObject
{
    #[CastWith(DateCaster::class, format: 'Y-m-d')]
    public Carbon $date;
}
```

### Int

[](#int)

The IntCaster casts the provided value to an integer using (int) cast.

### Trim

[](#trim)

The TrimCaster will trim the provided value, so no whitespace remains around the value.

### UppercaseFirst

[](#uppercasefirst)

The UppercaseFirstCaster will uppercase the first letter of the provided value, similar to php's [ucfirst function](https://www.php.net/manual/en/function.ucfirst.php).

Optionally, the caster can lowercase the rest of the string, like so.

```
use Morningtrain\DataTransferObjectCasters\Casters\UppercaseFirstCaster;

class DTO extends DataTransferObject
{
    #[CastWith(UppercaseFirstCaster::class, lower: true)]
    public string $ucFirstString;
}
```

If the provided value is not a string, it will return the provided value.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

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

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

[](#contributing)

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

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [SimonJnsson](https://github.com/SimonJnsson)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~245 days

Total

3

Last Release

1145d ago

Major Versions

1.1.0 → 2.0.02023-03-24

### Community

Maintainers

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

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

![](https://www.gravatar.com/avatar/26a15e64fdf0498cb20d749d27ad48d095e842f8ac7c5d285248729a7d0e3e53?d=identicon)[SimonJnsson](/maintainers/SimonJnsson)

---

Top Contributors

[![SimonBarrettACT](https://avatars.githubusercontent.com/u/57679318?v=4)](https://github.com/SimonBarrettACT "SimonBarrettACT (4 commits)")[![SimonJnsson](https://avatars.githubusercontent.com/u/11147193?v=4)](https://github.com/SimonJnsson "SimonJnsson (4 commits)")[![peterbrinck](https://avatars.githubusercontent.com/u/6154068?v=4)](https://github.com/peterbrinck "peterbrinck (3 commits)")

---

Tags

laravelmorningtraindata-transfer-object-casters

###  Code Quality

TestsPest

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/morningtrain-data-transfer-object-casters/health.svg)

```
[![Health](https://phpackages.com/badges/morningtrain-data-transfer-object-casters/health.svg)](https://phpackages.com/packages/morningtrain-data-transfer-object-casters)
```

###  Alternatives

[spatie/laravel-data

Create unified resources and data transfer objects

1.7k28.9M627](/packages/spatie-laravel-data)[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[hirethunk/verbs

An event sourcing package that feels nice.

513162.9k6](/packages/hirethunk-verbs)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

123544.7k](/packages/worksome-exchange)[ralphjsmit/livewire-urls

Get the previous and current url in Livewire.

82270.3k4](/packages/ralphjsmit-livewire-urls)[hydrat/filament-table-layout-toggle

Filament plugin adding a toggle button to tables, allowing user to switch between Grid and Table layouts.

6292.3k1](/packages/hydrat-filament-table-layout-toggle)

PHPackages © 2026

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