Giter Club home page Giter Club logo

laravel-db-enum-generator's Introduction

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.

laravel-db-enum-generator's People

Contributors

richarddobron avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.