Laravel 6 , Laravel , Laravel 7
In this blog, I will show how to response download file from storage example. We sometimes require to return response with download file from controller method like generate invoice and give to download or etc.
We will explain response download fill in the storage.In First argument of download() we have to give path of download file. We can rename of download file by passing second argument of download(). We can also set headers of file by passing third argument.I have to add one method "downloadFile()" in my downloadfilecontroller.
In here example to response download file from storage.
So, first I am create route for our example.
Now In this controller downloadFile() metod to response download file from storage.
class DownloadFileController extends Controller
public function downloadFile()
$myFile = public_path("dummy.pdf");
$headers = ['Content-Type: application/pdf'];
$newName = 'nicesnippets-pdf-file-'.time().'.pdf';
return response()->download($myFile, $newName, $headers);
it will help you..