mindtwo/laravel-enumerable

This package is abandoned and no longer maintained. The author suggests using the bensampo/laravel-enum package instead.

Laravel Enumerable

3.1.0 2020-03-23 14:24 UTC

This package is auto-updated.

Last update: 2020-09-21 16:11:21 UTC


README

Build Status StyleCI Quality Score Latest Stable Version Total Downloads License

Installation

You can install the package via composer:

composer require mindtwo/laravel-enumerable

How to use?

Setting up enumerable objects

This package based on BenSampo/laravel-enum. Take a look at its Documentation to set up your enumerable objects.

Prepare eloquent model

There are two ways to use this package. The simplest way is to extend the EnumerableModel which is shipped with this package.

namespace example;

use mindtwo\LaravelEnumerable\Models\EnumerableModel

class exampleModel extends EnumerableModel
{
}

If you prefer, you can directly use the Enumerable trait in your models. Be sure to implement the EnumerableInterface, too.

namespace example;

use Illuminate\Database\Eloquent\Model;
use mindtwo\LaravelEnumerable\Interfaces\EnumInterface;
use mindtwo\LaravelEnumerable\Models\Traits\Enumerable;


class exampleModel extends Model implements EnumInterface
{
    use Enumerable;
}

Configure eloquent model

To configure enumerable attributes simply set up a property named 'enums' as array. The key contains the attribute name. The value is set to the enumerable class name you like to use for that attribute.

namespace example;

use mindtwo\LaravelEnumerable\Models\EnumerableModel

class exampleModel extends EnumerableModel
{
    public $enums = [
        'examle_attribute' => ExampleEnum::class
    ];
}

Important: Since package version 1.1.0 the $enums property must be declared as public!

Now you can use Laravel's regular attribute set and fill functions to set the attribute value. If the value is not configured in the given enum object, an InvalidEnumValueException is thrown.

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email info@mindtwo.de instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.