g4t/enum

0.0.1 2022-02-08 21:03 UTC

This package is auto-updated.

Last update: 2024-05-09 02:23:45 UTC


README

This package offers strongly typed enums in PHP. In this package we will change the value coming from the database and entered into it

Installation

Via Composer

composer require g4t/enum
php artisan vendor:publish --provider=g4t\Enum\EnumServiceProvider

Usage

use the following code in model

use g4t\Enum\Status;
.
.
.

protected $casts = [
  'column_name' => Status::class,
];

now go to config/enum.php you well find this example there:

In the following code, the key is the value allowed in the database
and value is the format to be output instead of the one in the database
<?php

return [
    '1' => 'active',
    '2' => 'inactive'
];

License

MIT. Please see the license file for more information.