Files
autocrm/app/Filament/Tenant/Resources/LaborCategoryResource.php
T
Vasyka 1b34a3c217 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>
2026-09-07 12:37:39 +00:00

113 lines
3.6 KiB
PHP

<?php
namespace App\Filament\Tenant\Resources;
use App\Filament\Tenant\Resources\LaborCategoryResource\Pages;
use App\Models\Tenant\LaborCategory;
use Filament\Actions;
use Filament\Forms;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Tables;
use Filament\Tables\Table;
class LaborCategoryResource extends Resource
{
protected static ?string $model = LaborCategory::class;
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-tag';
public static function getNavigationLabel(): string
{
return __('Categorii manopere');
}
public static function getNavigationGroup(): ?string
{
return __('nav.group.Service');
}
public static function getModelLabel(): string
{
return __('categorie');
}
public static function getPluralModelLabel(): string
{
return __('Categorii manopere');
}
protected static ?int $navigationSort = 33;
public static function form(Schema $schema): Schema
{
return $schema->components([
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 afișare'))
->numeric()
->default(0),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('sort_order')
->label('#')
->sortable()
->alignRight()
->width(50),
Tables\Columns\TextColumn::make('name_ro')
->label('RO')
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('name_ru')
->label('RU')
->placeholder('—'),
Tables\Columns\TextColumn::make('name_en')
->label('EN')
->placeholder('—'),
])
->defaultSort('sort_order')
->reorderable('sort_order')
->actions([
Actions\EditAction::make(),
Actions\DeleteAction::make(),
])
->bulkActions([]);
}
public static function getPages(): array
{
return [
'index' => Pages\ListLaborCategories::route('/'),
'create' => Pages\CreateLaborCategory::route('/create'),
'edit' => Pages\EditLaborCategory::route('/{record}/edit'),
];
}
}