*/ public function rules(): array { return $this->isMethod('PATCH') ? PartialUpdate::rules($this->formRules()) : $this->formRules(); } /** * The rules a whole record is checked by: the edit form's, and a PUT's. * * @return array */ public function formRules(): array { return parent::rules(); } /** * What only updating checks. * * @return array */ protected function modeRules(): array { return [ // Fixed once created: sent back as stored, or not at all. 'sku' => ['sometimes', new Unchanged($this->record())], ]; } /** The record being updated. */ protected function record(): ?Product { $record = $this->route('product'); return $record instanceof Product ? $record : null; } /** * The record being edited already holds its own values, so it has to be * exempted or every save would fail as a duplicate of itself. */ protected function unique(string $column): Unique { return Rule::unique('products', $column)->ignore($this->route('product')); } }