0

I have stored my pdf file in files folder inside public folder. Now, i have a "Download" button inside resources/views/admin/view_data.blade.php

How to download the pdf file when i click the download button??

2 Answers2

2

Try this. When you click on the button call a route and a method then use this code. You can change directory path.

public function getDownload()
{
  //PDF file is stored under project/public/download/info.pdf
  $file= public_path(). "/download/info.pdf";

  $headers = array(
          'Content-Type: application/pdf',
        );

    return Response::download($file, 'filename.pdf', $headers);
}
Web Artisan
  • 1,870
  • 3
  • 23
  • 33
0

Just a small addition, if you are using an IDE the following will prevent any squarks return response()->download($file, 'filename.pdf' ,$headers);

cevizmx
  • 371
  • 1
  • 8
  • 24