g4t / enum
PHP Enums
0.0.1
2022-02-08 21:03 UTC
Requires
- illuminate/support: ~7|~9
Requires (Dev)
- orchestra/testbench: ~5|~6
- phpunit/phpunit: ~9.0
This package is auto-updated.
Last update: 2025-03-09 04:15:19 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.