10 months ago

Laravel dosen't redirect request

Posted 10 months ago by hsntngr

I'm trying to do redirection in AppServiceProvider. if url doesn't have any lang parameter, I want to add lang parameter and redirect request to updated url.. But nothing happens.

public function boot(Request $request)
        if (!$this->doNotLocalize($request)) {
            $langParameter = $request->segment(1);
            $supportedLanguages = config("translate.locales");
            if (strlen($langParameter) == 2) {
                $locale = $langParameter;
                if (in_array($locale, $supportedLanguages))
                else {
            } else {
                $locale = in_array($request->getPreferredLanguage(), $supportedLanguages) ?
                    $request->getPreferredLanguage() : config("translate.locale");
                $redirectTo = $locale . $request->getPathInfo();
                // Save any flashed data for redirect
                redirect($redirectTo, 302, ['Vary' => 'Accept-Language']);

Am I doing wrong or are we not able to redirect requests in service providers ?

Please sign in or create an account to participate in this conversation.