laravel-enum-cast maintained by rvxlab

Laravel Enum Cast
This package is no longer maintained
Native enums are supported as of PHP 8.1 and Laravel 8.71.0, as such I will no longer be maintaining this package.
Enum cast for Laravel Models using myclabs/php-enum.
Installation
Install through composer
composer require rvxlab/laravel-enum-cast
Usage
Add the CastsEnums trait to your model, add the EnumCast class to the $casts array and create an $enums array to tell which enum should be used.
class CarMake extends \MyCLabs\Enum\Enum
{
public const VOLKSWAGEN = 'volkswagen';
public const BMW = 'bmw';
}
class Car extends \Illuminate\Database\Eloquent\Model
{
use \RVxLab\LaravelEnumCast\CastsEnums;
protected $casts = [
'make' => \RVxLab\LaravelEnumCast\EnumCast::class,
];
protected $enums = [
'make' => CarMake::class,
];
}
That's it, you're all set!
License
This project uses the MIT License