LaravelPackages.net
Acme Inc.
Toggle sidebar
dobron/laravel-db-enum-generator

Database enum generator for Laravel.

7.556
3
1.0.3
About dobron/laravel-db-enum-generator

dobron/laravel-db-enum-generator is a Laravel package for database enum generator for laravel.. It currently has 3 GitHub stars and 7.556 downloads on Packagist (latest version 1.0.3). Install it with composer require dobron/laravel-db-enum-generator. Discover more Laravel packages by dobron or browse all Laravel packages to compare alternatives.

Last updated

Laravel Enum

Laravel package that introduces a new Artisan command to generate Enum classes fetched from database.

📖 Requirements

  • PHP 7.0 or higher
  • Laravel 5.6 or higher

📦 Install

Via Composer

$ composer require dobron/laravel-db-enum-generator --dev

⚡️ Usage

Enums can be generated by calling the Artisan command make:enum and specifying the class or table name, and columns for key and value(s).

| Id | Slug | Role | |-----|------------------|------------| | 1 | MANAGER | Admin | | 2 | CONTENT_CREATOR | Editor | | 3 | MODERATOR | Moderator | | 4 | ADVERTISER | Advertiser | | 5 | INSIGHTS_ANALYST | Analyst |

$ php artisan make:enum App\Enums\UserRoleTypes --model=UserRole --id=Id --slug=Slug --title=Role
<?php

namespace App\Enums;

class UserRoleTypes
{
    public const MANAGER = 1;
    public const CONTENT_CREATOR = 2;
    public const MODERATOR = 3;
    public const ADVERTISER = 4;
    public const INSIGHTS_ANALYST = 5;

    public static function map(): array
    {
        return [
            static::MANAGER => 'Admin',
            static::CONTENT_CREATOR => 'Editor',
            static::MODERATOR => 'Moderator',
            static::ADVERTISER => 'Advertiser',
            static::INSIGHTS_ANALYST => 'Analyst',
        ];
    }
}

⚙️ Options

| Option | Description | Default | |--------|--------------------------------------------------|---------| | model | Eloquent model class name | | | table | (or) The database table name | | | path | The path to generate enums in | | | id | ID column name | id | | slug | Slug column name | slug | | value | Column(s) name for map separated by comma | | | force | Create the class even if the enum already exists | false |

📅 Change log

Please see CHANGELOG for more information on what has changed recently.

🧪 Testing

$ composer test

🤝 Contributing

Please see CONTRIBUTING for details.

🙋 Credits

⚖️ License

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

Comments