PHP code example of bjerke / laravel-enums
1. Go to this page and download the library: Download bjerke/laravel-enums 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/ */
bjerke / laravel-enums example snippets
namespace App\Enums;
use Bjerke\Enum\HasTranslations;
use Bjerke\Enum\UsesTranslations;
enum PostStatus: int implements HasTranslations {
use UsesTranslations;
case DRAFT = 10;
case PUBLISHED = 20;
case ARCHIVED = 30;
}
// ../resources/lang/en/enum.php
use App\Enums\MyEnum;
return [
'post_status' => [
PostStatus::DRAFT->value => 'Draft',
PostStatus::PUBLISHED->value => 'Published'
PostStatus::ARCHIVED->value => 'Archived'
]
];
PostStatus::DRAFT->translate(); // return translation for this case
PostStatus::getTranslations(); // return all translations