302 Not found

Abdalmalek Shd - Nov 1 - - Dev Community

I'm working with Laravel and I'm having trouble with a 302 Found status. I'm using a GET route that changes the language, saves the session, then redirects back or to the dashboard if there's no HTTP referrer. The code and route work fine in another project on the server, so I'm not sure what the issue is. I've tried clearing config cache, route cache, and other caches, but the problem persists. I also tried changing the URL, but the issue remains. Any ideas on what could be causing this?
That's the code guys.

Route::get('/switch_language/{language}', [SubscriptionHomeController::class, 'switch_lang']);


 public function switch_lang($language = "")
    {


        session()->put('my_site_lang', $language);
        session()->save();


        if (!empty($_SERVER['HTTP_REFERER'])) {
            return redirect($_SERVER['HTTP_REFERER']);
        } else {
            return redirect('/subscription/dashboard');
        }
    }
//Blade code
    @foreach (get_language() as $lang)
                            <li><a href="{{url('subscription/switch_lang/' . $lang->slug)}}"><span> {{$lang->name}} </span> </a></li>
                             @endforeach
Enter fullscreen mode Exit fullscreen mode
.
Terabox Video Player