Looking to hire Laravel developers? Try LaraJobs

laravel-enum-cast maintained by rvxlab

Description
Enum casts for Laravel
Last update
2022/02/13 02:23 (dev-main)
License
Links
Downloads
1 097

Comments
comments powered by Disqus

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