bbprojectnet / laravel-casts
Additional casts classes for Laravel.
1.4.0
2026-08-07 19:47 UTC
Requires
- php: >=8.3.0
- illuminate/collections: ^13.0
- illuminate/contracts: ^13.0
- illuminate/database: ^13.0
- illuminate/support: ^13.0
Requires (Dev)
- mockery/mockery: ^1.6
- phpunit/phpunit: ^12.0
README
This package provides some additional castable classes for Laravel.
Requirements
- PHP 8.3 and above
- Laravel 13
Installation
Require this package with composer using the following command:
composer require bbprojectnet/laravel-casts
Casts
AsEnumArray
Casts a value (json) to a array of Enums.
protected $casts = [ 'roles' => AsEnumArray::class . ':' . Role::class, ];
AsEnumCollection
Casts a value (json) to a Laravel Collection of Enums.
protected $casts = [ 'roles' => AsEnumCollection::class . ':' . Role::class, ];
AsHash
Saves the value as a hash using the Laravel Hash facade. As of Laravel 10, same as hashed cast.
protected $casts = [ 'password' => AsHash::class, ];
AsInterval
Casts a seconds value (integer) as a CarbonInterval class.
protected $casts = [ 'timeout' => AsInterval::class, ];
AsStrictArray
Same as array, except that a null value is cast to an empty array. Similarly, an empty array is stored in the database as null.
protected $casts = [ 'items' => AsStrictArray::class, ];
AsTimeZone
Cast a value (string) as a DateTimeZone class.
protected $casts = [ 'timezone' => AsTimeZone::class, ];
License
The Laravel casts package is open-sourced software licensed under the MIT license.