cannot('upload', $upload->getMorph()->getPathModel())) { return $this->errFobidden(__('Access is denied')); } if ($upload->getStorageType()->isImage() !== true) { return $this->errValidate(__('storage.Trying to upload a wrong image')); } try { $storage = DB::transaction(function () use ($upload, $user) { $storage = $this->storageCommandHandler->handleStore( upload: $upload, user: $user, ); return $this->imageResize($storage, $this->maxImageWidth, $this->maxImageHeight); }); } catch (\Throwable $e) { report($e); return $this->errService(__('Server Error')); } return new UploadResult($storage); } private function imageResize(Storage $storage, ?int $width, ?int $height): Storage { if (empty($width) && empty($height)) { return $storage; } if (!empty($width) && !empty($height)) { return $this->resizeCommandHandler->resize($storage, $width, $height); } if (!empty($height)) { return $this->resizeCommandHandler->height($storage, $height); } return $this->resizeCommandHandler->width($storage, $width); } }