company_id) ? Company::getIdForCurrentUser($this->company_id) : $this->company_id; $this->parseLastAuditDate(); $this->merge([ 'asset_tag' => $this->asset_tag ?? Asset::autoincrement_asset(), 'company_id' => $idForCurrentUser, 'purchase_cost' => $this->filled('purchase_cost') && ! is_float($this->input('purchase_cost')) && preg_match('/^[\d.,]+$/', (string) $this->input('purchase_cost')) ? Helper::ParseCurrency($this->input('purchase_cost')) : $this->input('purchase_cost'), ]); } /** * Get the validation rules that apply to the request. */ public function rules(): array { $modelRules = (new Asset)->getRules(); return array_merge( $modelRules, ['status_id' => [new AssetCannotBeCheckedOutToNondeployableStatus]], parent::rules(), ); } private function parseLastAuditDate(): void { if ($this->input('last_audit_date')) { try { $lastAuditDate = Carbon::parse($this->input('last_audit_date')); $this->merge([ 'last_audit_date' => $lastAuditDate->startOfDay()->format('Y-m-d H:i:s'), ]); } catch (InvalidFormatException $e) { // we don't need to do anything here... // we'll keep the provided date in an // invalid format so validation picks it up later } } } }