isEmpty($row, $this->type . '_number')) { return []; } $row = parent::map($row); $row['type'] = $this->type === Document::INVOICE_TYPE ? 'income' : 'expense'; $row['account_id'] = $this->getAccountId($row); $row['category_id'] = $this->getCategoryId($row, $this->type === Document::INVOICE_TYPE ? 'income' : 'expense'); $row['contact_id'] = $this->getContactId($row, $this->type === Document::INVOICE_TYPE ? 'customer' : 'vendor'); $row['document_id'] = $this->getDocumentId($row); return $row; } public function rules(): array { $rules = (new Request())->rules(); if ($this->type === Document::INVOICE_TYPE) { $rules['invoice_number'] = 'required|string'; } else { $rules['bill_number'] = 'required|string'; } return $rules; } }