file = $uploadedFile; $this->data = $data; $fileName = $this->getStrategy()->sourceFileBasename($this->file, $this->data); $sourcePath = $this->getStrategy()->sourcePath($fileName); $fileName = $this->transformFileName($sourcePath, $fileName).'.'.$this->file->getClientOriginalExtension(); $uploadedFile->storeAs($sourcePath, $fileName, $this->disk); Queue::push(CompressJob::class, [ 'path' => $sourcePath, 'filename' => $fileName, 'disk' => $this->disk, 'strategy' => $this->strategy, 'crop' => $this->data['crop'] ]); return $fileName; } private function storage() { return Storage::disk($this->disk); } private function transformFileName($path, $basename) { if (count(glob($this->storage()->path($path).'/'.$basename.'*')) == 0) { return $basename; } $i = 1; while(count(glob($this->storage()->path($path).'/'.$basename.'-'.$i.'*')) != 0) { $i++; } return $basename.'-'.$i; } private function originalExtension() { return $this->file->getClientOriginalExtension(); } private function getStrategy() { return app($this->strategy); } }