user(); return $user->can('create', Product::class); } public function rules() { if ($this->file('documents') && is_array($this->file('documents'))) { $rules['documents.*'] = $this->fileValidation(); } elseif ($this->file('documents')) { $rules['documents'] = $this->fileValidation(); }else { $rules['documents'] = 'bail|sometimes|array'; } if ($this->file('file') && is_array($this->file('file'))) { $rules['file.*'] = $this->fileValidation(); } elseif ($this->file('file')) { $rules['file'] = $this->fileValidation(); } $rules['cost'] = 'sometimes|numeric'; $rules['price'] = 'sometimes|numeric'; $rules['quantity'] = 'sometimes|numeric'; $rules['in_stock_quantity'] = 'sometimes|numeric'; $rules['stock_notification_threshold'] = 'sometimes|numeric'; $rules['stock_notification'] = 'sometimes|bool'; return $rules; } public function prepareForValidation() { $input = $this->all(); if (! isset($input['quantity'])) { $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); } }