user()->can('create', RecurringQuote::class); } public function rules() { $rules = []; if($this->file('documents') && is_array($this->file('documents'))) $rules['documents.*'] = $this->file_validation; elseif($this->file('documents')) $rules['documents'] = $this->file_validation; if ($this->file('file') && is_array($this->file('file'))) { $rules['file.*'] = $this->file_validation; } elseif ($this->file('file')) { $rules['file'] = $this->file_validation; } $rules['client_id'] = 'required|exists:clients,id,company_id,'.auth()->user()->company()->id; $rules['invitations.*.client_contact_id'] = 'distinct'; $rules['frequency_id'] = 'required|integer|digits_between:1,12'; $rules['number'] = new UniqueRecurringQuoteNumberRule($this->all()); return $rules; } public function prepareForValidation() { $input = $this->all(); $input = $this->decodePrimaryKeys($input); $input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : []; if (isset($input['auto_bill'])) { $input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']); } else { if ($client = Client::find($input['client_id'])) { $input['auto_bill'] = $client->getSetting('auto_bill'); $input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']); } } $this->replace($input); } private function setAutoBillFlag($auto_bill) { if ($auto_bill == 'always' || $auto_bill == 'optout') { return true; } return false; } public function messages() { return []; } }