Taylor
Taylor

Reputation: 3141

Laravel download file not working - Argument 3 passed to Illuminate\Routing\ResponseFactory::download() must be of the type

I am trying to get the user to download a file.

The error message I'm getting:

Argument 3 passed to Illuminate\Routing\ResponseFactory::download() must be of the type array, null given, called in

My code:

 $file = Uploads::where(['username' => $username, 'id' => $id])->firstOrFail();

    return response()->download($file->path, $file->name, header('Content-Type', $file->mime));

I have no idea why.

Upvotes: 0

Views: 1629

Answers (1)

lagbox
lagbox

Reputation: 50481

You are getting that because you are not passing an array as the third argument. header() is a PHP function for sending a raw HTTP header, it does not return anything.

If you want to use that 3rd argument for download you would need to pass it an array, but you should try to see if download method can set the correct headers for you without passing the 3rd argument and if not then pass your own headers.

Upvotes: 1

Related Questions