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

v1.0.0 2018-12-01 11:44 UTC

This package is auto-updated.

Last update: 2024-10-29 05:22:49 UTC


README

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.