user(); return $user->can('create', Project::class); } public function rules() { /** @var \App\Models\User $user */ $user = auth()->user(); $rules = []; $rules['name'] = 'required'; $rules['client_id'] = 'required|exists:clients,id,company_id,'.$user->company()->id; if (isset($this->number)) { $rules['number'] = Rule::unique('projects')->where('company_id', $user->company()->id); } if ($this->file('documents') && is_array($this->file('documents'))) { $rules['documents.*'] = $this->file_validation; } elseif ($this->file('documents')) { $rules['documents'] = $this->file_validation; }else { $rules['documents'] = 'bail|sometimes|array'; } if ($this->file('file') && is_array($this->file('file'))) { $rules['file.*'] = $this->file_validation; } elseif ($this->file('file')) { $rules['file'] = $this->file_validation; } return $this->globalRules($rules); } public function prepareForValidation() { $input = $this->decodePrimaryKeys($this->all()); if (array_key_exists('color', $input) && is_null($input['color'])) { $input['color'] = ''; } $this->replace($input); } public function getClient($client_id) { return Client::withTrashed()->find($client_id); } }