laravellaravel-5laravel-5.4laravel-5.5laravel-response

Laravel 5.5 file download Call to undefined method BinaryFileResponse::withCookie()


After upgrading to Laravel 5.5, this code:

    $headers = ['Content-Type: ' . $fileData[2]];
    return Response::download($fileData[0], $fileData[1] ,$headers);

generates this error:

Call to undefined method Symfony\Component\HttpFoundation\BinaryFileResponse::withCookie()

in CreateFreshApiToken.php (line 51)
at CreateFreshApiToken->handle(object(Request), object(Closure))
in Pipeline.php (line 149)

Any idea? Might it be a bug? It worked well with Laravel 5.4.


Solution

  • You should verify what CreateFreshApiToken.php does. Response::download is returning Symfony\Component\HttpFoundation\BinaryFileResponse and this class doesn't have withCookie method. In Laravel 5.4 it seems it was exactly the same. If it won't help include this class code and what middleware are you using in App\Http\Kernel.php file.

    It seems something was broken in Laravel Passport in this PR http://github.com/laravel/passport/pull/474 . You can also look at http://github.com/laravel/passport/issues/489 and maybe remove this route from web middleware if it's possible as a temporary fix and wait for making fix in Laravel Passport