lopatin96/laravel-trans-enum

Laravel trans enum

1.0.6 2024-10-04 08:17 UTC

This package is auto-updated.

Last update: 2024-12-04 08:36:11 UTC


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();