Add multilingual support to labor categories (RO/RU/EN)

- Migration: adds name_ro, name_ru, name_en columns; copies name→name_ro;
  seeds RU and EN translations for all 11 default categories
- LaborCategory: label() returns localized name, optionsForSelect() keyed
  by canonical name (stored in labors.category) with localized label
- LaborCategoryResource: 3-column form with RO/RU/EN inputs; table shows
  all three columns side by side
- LaborResource: category select and filter use optionsForSelect()

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-09-07 12:37:39 +00:00
parent 818ae29b20
commit 1b34a3c217
4 changed files with 102 additions and 17 deletions
@@ -42,13 +42,31 @@ class LaborCategoryResource extends Resource
public static function form(Schema $schema): Schema
{
return $schema->components([
Forms\Components\TextInput::make('name')
->label(__('Denumire'))
->required()
->maxLength(80)
->columnSpanFull(),
Forms\Components\Section::make(__('Denumire'))
->columns(3)
->schema([
Forms\Components\TextInput::make('name_ro')
->label(__('Română (RO)'))
->required()
->maxLength(80)
->live(onBlur: true)
->afterStateUpdated(function ($state, callable $set, $get) {
// Auto-fill canonical name from name_ro
if (! $get('name')) {
$set('name', $state);
}
}),
Forms\Components\TextInput::make('name_ru')
->label(__('Rusă (RU)'))
->maxLength(80),
Forms\Components\TextInput::make('name_en')
->label(__('Engleză (EN)'))
->maxLength(80),
]),
Forms\Components\Hidden::make('name')
->dehydrateStateUsing(fn ($state, $get) => $state ?: $get('name_ro')),
Forms\Components\TextInput::make('sort_order')
->label(__('Ordine'))
->label(__('Ordine afișare'))
->numeric()
->default(0),
]);
@@ -63,15 +81,16 @@ class LaborCategoryResource extends Resource
->sortable()
->alignRight()
->width(50),
Tables\Columns\TextColumn::make('name')
->label(__('Categorie'))
Tables\Columns\TextColumn::make('name_ro')
->label('RO')
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('updated_at')
->label(__('Modificat'))
->dateTime('d.m.Y')
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('name_ru')
->label('RU')
->placeholder('—'),
Tables\Columns\TextColumn::make('name_en')
->label('EN')
->placeholder('—'),
])
->defaultSort('sort_order')
->reorderable('sort_order')
@@ -80,7 +99,6 @@ class LaborCategoryResource extends Resource
Actions\DeleteAction::make(),
])
->bulkActions([]);
}
public static function getPages(): array
@@ -53,7 +53,7 @@ class LaborResource extends Resource
->schema([
Forms\Components\Select::make('category')
->label(__('Categorie'))
->options(fn () => \App\Models\Tenant\LaborCategory::orderBy('sort_order')->orderBy('name')->pluck('name', 'name'))
->options(fn () => \App\Models\Tenant\LaborCategory::optionsForSelect())
->required()
->searchable(),
Forms\Components\TextInput::make('code')->label(__('Cod'))->maxLength(32),
@@ -100,7 +100,7 @@ class LaborResource extends Resource
])
->filters([
Tables\Filters\SelectFilter::make('category')
->options(fn () => \App\Models\Tenant\LaborCategory::orderBy('sort_order')->orderBy('name')->pluck('name', 'name')),
->options(fn () => \App\Models\Tenant\LaborCategory::optionsForSelect()),
Tables\Filters\TernaryFilter::make('is_active')->label(__('Doar active')),
])
->actions([