path = $path ?? 'exports'; } /** * Execute the job. */ public function handle() { $tempFileName = null; try { $tempFileName = app(ExportAccount::class) ->execute([ 'account_id' => Auth::user()->account_id, 'user_id' => Auth::user()->id, ]); // get the temp file that we just created $tempFilePath = disk_adapter('local')->getPathPrefix().$tempFileName; // move the file to the public storage return Storage::disk(self::STORAGE) ->putFileAs($this->path, new File($tempFilePath), basename($tempFileName)); } finally { // delete old file from temp folder $storage = Storage::disk('local'); if ($storage->exists($tempFileName)) { $storage->delete($tempFileName); } } } }