lopatin96 / laravel-trans-enum
Laravel trans enum
Installs: 2 185
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=8.0
Requires (Dev)
- orchestra/testbench: ^8.0
README
Install
When you have an enums like App\Enums\Smoking.php
, create an \lang\en\enums\smoking.php
file with locals.
<?php namespace App\Enums; enum Smoking: string { case Never = 'never'; case Occasional = 'occasional'; case Often = 'often'; }
<?php return [ 'never:title' => 'Never', 'never:description' => 'Some description for Never', 'occasional:title' => 'Occasional smoker', 'often:title' => 'Often', ];
Trait
Add HasTrans trait to your Enum to add trans(): string
function.
namespace App\Enums; use Atin\LaravelTransEnum\Traits\HasTrans; enum Smoking: string { use HasTrans, …
Usage
echo Smoking::Never->title(); echo Smoking::Never->description();