diff($exportedFiles)->first(); if (!$exportedFile) { response()->redirectToRoute('bo.dashboard')->withErrors([ 'Export failed to catch the exported file' ])->throwResponse(); } /** @var \Symfony\Component\Finder\SplFileInfo $exportedFile */ return response()->streamDownload(function () use ($exportedFile) { echo $exportedFile->getContents(); }, $exportedFile->getBasename(), [ 'Content-Type' => File::mimeType($exportedFile->getRealPath()) ]); } }