> */ public function rules(): array { $company = $this->header('company'); $nameIsFree = $this->isMethod('PUT') ? Rule::unique('notes') ->ignore($this->route('note')->id) ->where('type', $this->type) ->where('company_id', $company) : Rule::unique('notes') ->where('company_id', $company) ->where('type', $this->type); return [ 'type' => ['required'], 'name' => ['required', $nameIsFree], 'notes' => ['required'], 'is_default' => ['required'], ]; } /** * The validated attributes, stamped with the company from the request * header. A `company_id` sent by the client is not among them — it is not * a validated key, so it never survives this far. */ public function getNotesPayload() { $attributes = $this->validated(); $attributes['company_id'] = $this->header('company'); return $attributes; } }