*/ public function rules(): array { $genre = $this->route('genre'); $organisationId = $genre instanceof Genre ? $genre->organisation_id : ($this->route('organisation')?->id ?? null); $genreId = $genre instanceof Genre ? $genre->id : null; return [ 'name' => [ 'sometimes', 'required', 'string', 'max:40', Rule::unique('genres', 'name') ->where('organisation_id', $organisationId) ->ignore($genreId), ], 'color' => ['sometimes', 'nullable', 'string', 'size:7', 'regex:/^#[0-9A-Fa-f]{6}$/'], 'sort_order' => ['sometimes', 'nullable', 'integer', 'min:0'], 'is_active' => ['sometimes', 'boolean'], ]; } }