Download PDF on external URL via Laraval

If you have the URL of PDF which is situated on some other domain. You can allow it to be downloaded via your laravel application with following code


$pdf = file_get_contents('http://www.africau.edu/images/default/sample.pdf');
Storage::disk('local')->put('samplepdf.pdf', $pdf);
return response()->download(storage_path().'/app/samplepdf.pdf')->deleteFileAfterSend(true);

Get the file contents to your local server and save it as pdf via Storage facade. Return the download in the response and delete once downloaded.

That’s about it.

Site Footer