user()->can('create', Product::class); } public function rules() { if ($this->input('documents') && is_array($this->input('documents'))) { $documents = count($this->input('documents')); foreach (range(0, $documents) as $index) { $rules['documents.' . $index] = 'file|mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx|max:20000'; } } elseif ($this->input('documents')) { $rules['documents'] = 'file|mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx|max:20000'; } $rules['cost'] = 'numeric'; $rules['price'] = 'numeric'; $rules['quantity'] = 'numeric'; return $rules; } protected function prepareForValidation() { $input = $this->all(); if (!isset($input['quantity']) || $input['quantity'] < 1) { $input['quantity'] = 1; } if (array_key_exists('assigned_user_id', $input) && is_string($input['assigned_user_id'])) { $input['assigned_user_id'] = $this->decodePrimaryKey($input['assigned_user_id']); } $this->replace($input); } }