getCurrentPanel returning wrong panel

I’ve two panels - company and seeker. Both appear to be working correctly until I call Filament::getCurrentPanel()->getId() in a middleware I am using to apply global scopes. It always returns company. My goal is to apply different global scopes based on the active panel to limit access to certain records.

class ApplyApplicantScopes
{
    public function handle(Request $request, Closure $next): Response
    {
        // dump(Filament::getCurrentPanel()->getId());

        if (Filament::getCurrentPanel()->getId() === 'seeker') {
            Application::addGlobalScope(
                fn(Builder $query) => $query->whereBelongsTo(auth()->user()),
            );
        }

        return $next($request);
    }
}


// company
return $panel
    ->default()
    ->tenant(Team::class)
    ->id('company')
    ->path('company')
    ...


// seeker
return $panel
    ->id('seeker')
    ->path('seeker')
    ...
image.png
Solution
Fixed it. I was applying my middleware in the Laravel kernel file, not the middleware section of the panel’s config.

So it looks like the default panel is loaded by Laravel then replaced later.

return $panel
    ->id('seeker')
    ->path('seeker')
    ...
    ->middleware([
        EncryptCookies::class,
        ...
        ApplyApplicantScopes::class,
    ])


Panel middleware means I don’t even need to do the check in my middleware code, that’s already done!
Was this page helpful?