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 tables()
{
return [
'table_name' => 'enum_column'
]
}
}
return [
...
'post_migrate' => false,
...
]
use IsapOu\EnumHelpers\Contracts\UpdatableEnumColumns;
enum ExampleEnum: string implements JsConvertibleEnum
{
case ENUM_ONE = 'enum_one';
case ENUM_TWO = 'enum_two';
}
use IsapOu\EnumHelpers\Concerns\HasLabel;
enum ExampleEnum: string
{
use HasLabel;
case ENUM_ONE = 'enum_one';
case ENUM_TWO = 'enum_two';
}
ExampleEnum::ENUM_ONE->getLabel()
protected function getPrefix(): ?string
{
return 'prefix';
}
protected function getNamespace(): ?string
{
return 'namespace';
}
use Filament\Support\Contracts\HasLabel;
enum ExampleEnum: string implements HasLabel
{
use HasLabel;
case ENUM_ONE = 'enum_one';
case ENUM_TWO = 'enum_two';
}