Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LocaleCookieRedirect throws exception when returning file response #804

Open
ridea-co opened this issue Nov 12, 2021 · 3 comments
Open

LocaleCookieRedirect throws exception when returning file response #804

ridea-co opened this issue Nov 12, 2021 · 3 comments
Labels

Comments

@ridea-co
Copy link

If LocaleCookieRedirect is added to the Kernel, it throws exception when returning BinaryFileResponse, which does not have "withCookie" method at line 30
1636694792149

Current work around :

  1. Create a new class by copy & paste LocaleCookieRedirect
  2. Check and bypass if withCookie method does not exist
  3. Replace LocaleCookieRedirect with the newly created class in Kernel.php
        if (\count($params) > 0 && app('laravellocalization')->checkLocaleInSupportedLocales($params[0])) {
            $response = $next($request);

            if (method_exists($response, 'withCookie')) {
                return $response->withCookie(cookie()->forever('locale', $params[0]));
            } else {
                return $response;
            } // end of if

        } // end of if
@ijaureguialzo
Copy link

Hello @ridea-co, I was having this same issue and found that if you disable the middleware for that specific route, everything works again:

Route::get('/tutor/export', 'TutorController@export')
    ->withoutMiddleware('localeCookieRedirect')
    ->name('tutor.export');

@iwasherefirst2
Copy link
Collaborator

iwasherefirst2 commented Dec 19, 2021

@ridea-co yes your right. BinaryFileResponse does not have a withCookie method.
Instead of a if-else, we should just use $response->headers->set(...) because this works for BinaryFileResponse aswell for the default Laravel repsonse.

@mgralikowski
Copy link

Another clean workaround is using config:
'urlsIgnored' => ['*/download']
All routes (urls) are excluded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants