Anna Jeanine Anna Jeanine - 1 year ago 175
PHP Question

Stream a PDF file in Laravel 5.2

Hi everyone! I'm working on a Laravel 5.2 application in which the user can download a variety of files. One of these is a 'User guide', explaining how the website is set up and functionalities etc. I would like the PDF to be streamed in another page, so that the user is still within the application. The controller which I am using is:

public function userguidePDF(){

return response()->stream('../public/download/userguide.pdf');


But this returns:

Argument 1 passed to
Symfony\Component\HttpFoundation\StreamedResponse::__construct() must
be callable, string given, called in
on line 117 and defined

I have searched on the internet for a method, which leaded me to the following syntax:

return response()->stream($callback, 200, $headers);

Unfortunately, I am unable to find more documentation on the parameters because I don't understand them. Could someone please explain to me what the
$callback, 200, $header
are as parameters and how I can use this?

Answer Source

public function userguidePDF() {

    return response()->file(

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download