New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

dobron/laravel-db-enum-generator

Database enum generator for Laravel.
8,596 3
Install
composer require dobron/laravel-db-enum-generator
Latest Version:1.0.3
PHP:^7.0 || ^8.0
Laravel:5 – 10
License:MIT
Last Updated:Dec 29, 2023
Links: GitHub  ·  Packagist
Maintainer: dobron

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.

Related Packages

sloth-dev-guy/searches

Perform searches with Eloquent models using an array-like API setup

4,610 0
laragear/meta-model

Let other developers customize your package model and migrations

2,003,720 1
tusimo/embed-relation

a relation for laravel

10,942 3
pdphilip/opensearch

An OpenSearch implementation of Laravel's Eloquent ORM

467,689 0
designmynight/laravel-elasticsearch

Use Elasticsearch as a database in Laravel to retrieve Eloquent models and perfo...

45,415 30

Version History

Version Released PHP Laravel License
1.0.3 ^7.0 || ^8.0 ^5.6|^5.7|^5.8|^6.0|^7.0|^8.0|^9.0|^10.0 MIT
1.0.2 ^7.0 || ^8.0 ^5.6|^5.7|^5.8|^6.0|^7.0|^8.0|^9.0 MIT
1.0.1 ^7.0 || ^8.0 ^5.6|^5.7|^5.8|^6.0|^7.0|^8.0 MIT
1.0.0 ^7.1 ^5.6|^6.0|^7.0|^8.0 MIT