mohsentm/laravel-db-enum

laravel-db-enum is a trait for laravel models. use this trait on modules for getting the table fileds enum values
3,139 1
Install
composer require mohsentm/laravel-db-enum
Latest Version:v1.0.0
License:Apache-2.0
Last Updated:Apr 17, 2024
Links: GitHub  ·  Packagist
Maintainer: mohsentm

Get Enum values from database For Laravel

laravel-db-enum is a trait for laravel models. use this trait on modules for getting the table fileds enum values.

tags: laravel, lumen, eloquent, enum field

Installing

Pull this package via Composer.

    {
        "require": {
            "mohsentm/laravel-db-enum": "^1.*"
        }
    }
    

or run in terminal: composer require mohsentm/laravel-db-enum

Usage

use this trait use Mohsentm\EnumValue; your the model.

namespace App;

use Illuminate\Database\Eloquent\Model;
use Mohsentm\EnumValue;

class TestModal extends Model
{
	protected $table = "test";
    //Get enum value trait
  	use EnumValue;
}

then use getEnumValues() function to get enum values

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\TestModal;

class TestController extends Controller
{
	public function index(){
    	//return the array of table enum value list
		return TestModal::getEnumValues();
	}
}

result

{"user_status":["enable","disable"]}

Cache

To have best performance this package cache the result.

Contribute

Would you like to help with this project? Great! You don't have to be a developer, either. If you've found a bug or have an idea for an improvement, please open an issue and tell us about it.

If you are a developer wanting contribute an enhancement, bug fix or other patch to this project, please fork this repository and submit a pull request detailing your changes. We review all PRs! This open source project is released under the Apache 2.0 license which means if you would like to use this project's code in your own project you are free to do so. Speaking of, if you have used our code in a cool new project we would like to hear about it! Please send us an email.

License

Please refer to the LICENSE file that came with this project.

Related Packages

illuminatech/enum-seeder

Allows easy creation of DB seeders for the dictionary (enum) type tables

1,857 3
sedp-mis/laravel-db-commands

Laravel database commands

172 0
spatie/laravel-translation-loader

Store your language lines in the database, yaml or other sources

3,330,800 851
rolice/laravel-db-switch

Simple and light DB switcher for Laravel.

1,863 3
arcanedev/laravel-settings

This package allows you to persists configs/settings for Laravel projects.

139,802 74