Response download with file in Laravel 5.3 exampleBy Hardik Savani | September 21, 2016 | | 44592 Viewer | Category : Laravel
We sometimes require to return response with download file from controller method like generate invoice and give to download or etc. Laravel 5 provide us response() with download method that way we can do it.
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.
In bellow example will help you how it is works.
So, first i am going to create new route for our example as like bellow:
Ok, now i have to add one method "downloadFile()" in my HomeController. If you don't have HomeController then you can use your own controller as like bellow:
class HomeController extends Controller
public function downloadFile()
$myFile = public_path("dummy_pdf.pdf");
$headers = ['Content-Type: application/pdf'];
$newName = 'itsolutionstuff-pdf-file-'.time().'.pdf';
return response()->download($myFile, $newName, $headers);
So, maybe it can help you....
- How to generate UUID in Laravel 5 ?
- Bootstrap - Jquery multiple select with checkboxes example using bootstrap-multiselect.js plugin
- Laravel 5 - Class 'Input' not found issue?
- PHP AngularJS CRUD with Search and Pagination Example From Scratch
- How to add ckeditor with image upload in Laravel ?
- Solved - fatal: Failed to connect to bitbucket.org port 443: Network is unreachable
- How to get current page url in PHP?
- Jquery - How to copy text to clipboard without flash example ?