1b34a3c217
- 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>
34 lines
956 B
PHP
34 lines
956 B
PHP
<?php
|
|
|
|
namespace App\Models\Tenant;
|
|
|
|
use App\Models\Concerns\BelongsToTenant;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class LaborCategory extends Model
|
|
{
|
|
use BelongsToTenant;
|
|
|
|
protected $fillable = ['company_id', 'name', 'name_ro', 'name_ru', 'name_en', 'sort_order'];
|
|
|
|
protected $casts = ['sort_order' => 'integer'];
|
|
|
|
/** Localized display label — falls back through ru→en→name_ro→name. */
|
|
public function label(?string $locale = null): string
|
|
{
|
|
$locale = $locale ?: app()->getLocale();
|
|
return $this->{"name_{$locale}"}
|
|
?: $this->name_ro
|
|
?: $this->name
|
|
?: '';
|
|
}
|
|
|
|
/** Options array keyed by canonical name (stored in labors.category). */
|
|
public static function optionsForSelect(): array
|
|
{
|
|
return static::orderBy('sort_order')->orderBy('name')->get()
|
|
->mapWithKeys(fn ($c) => [$c->name => $c->label()])
|
|
->toArray();
|
|
}
|
|
}
|