PHP code example of isap-ou / laravel-enum-helpers
1. Go to this page and download the library: Download isap-ou/laravel-enum-helpers library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use IsapOu\EnumHelpers\Concerns\InteractWithCollection;
enum ExampleEnum: string
{
use InteractWithCollection;
case ENUM_ONE = 'enum_one';
case ENUM_TWO = 'enum_two';
}
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('table_name', function (Blueprint $table){
...
$table->enum('enum_column', ExampleEnum::values()->toArray());
...
});
}
}
use IsapOu\EnumHelpers\Contracts\UpdatableEnumColumns;
enum ExampleEnum: string implements UpdatableEnumColumns
{
case ENUM_ONE = 'enum_one';
case ENUM_TWO = 'enum_two';
public static function tables(): array
{
return [
'table_name' => 'enum_column'
];
}
}
/**
* Map "table_column" => enum case.
* The migrator will generate "... DEFAULT '<case->value>'".
*
* @return array<string, self>
*/
public static function tableColumnDefaults(): array
{
return [
'orders_status' => self::NEW,
'order_items_status' => self::NEW,
];
}
return [
...
'post_migrate' => false,
...
]
use IsapOu\EnumHelpers\Contracts\JsConvertibleEnum;
enum ExampleEnum: string implements JsConvertibleEnum
{
case ENUM_ONE = 'enum_one';
case ENUM_TWO = 'enum_two';
}
protected function getPrefix(): ?string
{
return 'prefix';
}
protected function getNamespace(): ?string
{
return 'namespace';
}
use Filament\Support\Contracts\HasLabel;
use IsapOu\EnumHelpers\Concerns\HasLabel as HasLabelTrait;
enum ExampleEnum: string implements HasLabel
{
use HasLabelTrait;
case ENUM_ONE = 'enum_one';
case ENUM_TWO = 'enum_two';
}