rvxlab/laravel-enum-cast

This package is abandoned and no longer maintained. No replacement package was suggested.

Enum casts for Laravel

1.1.1 2022-02-13 01:23 UTC

This package is auto-updated.

Last update: 2022-02-13 01:23:50 UTC


README

Laravel Enum Cast Banner, made with https://banners.beyondco.de

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