thesimons's avatar

Problem with a middleware

Hello,

I have problems with the following middleware.

The aim is whatever HTTP call outside https://my.site.com/profile/settings/spoken-languages/wizard (+ sub sections) would make sessions spoken_language_id and spoken_language_proficiency_id to be forgotten.

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

class ClearSpokenLanguageWizardSession
{
    public function handle(Request $request, Closure $next)
    {
        $response = $next($request);

        // If user navigates away from wizard routes, clear session keys
        if (! $request->is('profile/settings/spoken-languages/wizard*')) {
            session()->forget([
                'spoken_language_id',
                'spoken_language_proficiency_id',
            ]);
        }

        return $response;
    }
}

and it's registered in the following way into bootstrap/app.php

->withMiddleware(function (Middleware $middleware): void {
        $middleware->validateCsrfTokens(except: []);
        $middleware->append(ClearSpokenLanguageWizardSession::class);
    })

Thanks, Simon

0 likes
1 reply
thesimons's avatar

Fixed. The routes were inside a middleware for authentication. I have simply added ClearSpokenLanguageWizardSession as second middleware.

It's worked out properly.

Thanks, Simon

Please or to participate in this conversation.