sort_order; $old = (int) ($cat->getOriginal('sort_order') ?? PHP_INT_MAX); if ($new === $old) return; $conflict = static::withoutGlobalScope(TenantScope::class) ->where('company_id', $cat->company_id) ->where('sort_order', $new) ->where('id', '!=', $cat->id ?? 0) ->exists(); if ($conflict) { static::withoutGlobalScope(TenantScope::class) ->where('company_id', $cat->company_id) ->where('sort_order', '>=', $new) ->where('id', '!=', $cat->id ?? 0) ->increment('sort_order', 10); } }); } 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(); } }