Translation constants on blade

I’m working in app multilanguage.

I need translate a column status and write this code (below) but I think it’s not the best way

Model User

const STATUSES = [
        'active' => 'Active',
        'deleted' => 'Deleted',
        'suspended' => 'Suspended'
    ];

Blade template

<x-input.group for="email" label="{{ __('Status') }}" :error="$errors->first('editing.status')">
                    <x-input.select wire:model="editing.status" id="status">
                        @foreach(App\Models\User::STATUSES as $value => $label)
                            @php
                                $trans_value = __($label)
                            @endphp
                            <option value="{{ $value }}">{{ $trans_value }}</option>
                        @endforeach
                    </x-input.select>
                </x-input.group>

Any cleaner alternative?

Hey, @abkrim

You can do the following:

in your model, let’s assume you have a post model and in the migration:

$this->enum('status', ['active', 'deleted', 'sespended']);

in your model

public function scopeActive($builder)
{
  return $builder->where('status', 'active');
}

// do the same for the needed status

in the config/app.php add the following:

'status' => ['acitve', 'deleted', 'suspended'],

and in your blade you can do the following:

@foreach(config('app.status') as $status)
 <option value="{{ $status }}"> {{ ucfirst(__($status)) }} </option>
@endforeach

1 Like

Thanks.

I don’t use enum because problems with deployments. I don’t like enum columns… Is a string

$table->string('status',9)->default('active')->comment('active, suspended, deleted');

But after I see your code I see my despite with blade and “” . Translation is possible directly.

<option value="{{ $value }}">{{ __(ucfirst($value)) }}</option>

A lot of thanks,.

You are very welcome mate.