public function run($fields, RepositorieInterface $model, FormRequest $r) { $this->setModel($model); if (!is_array($fields)) { throw new BadMethodCallException("Argument fields in method UploadHelper::run must array"); } foreach ($fields as $field) { $files[$field] = $r->file($field); } if ($this->validate($files)) { foreach ($files as $field => $file) { if (!is_null($file)) { $name_file = $this->generateName($field, $file); $this->registerFile($field, $this->upload($file, $name_file)); } else { $this->registerFile($field, $this->generateName($field)); } } return true; } return false; }