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);
}
}
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')
...
// company
return $panel
->default()
->tenant(Team::class)
->id('company')
->path('company')
...
// seeker
return $panel
->id('seeker')
->path('seeker')
...
// seeker
return $panel
->id('seeker')
->path('seeker')
...
No description
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. ```php...
Jump to solution
1 Reply
Solution
Ric Le Poidevin
Ric Le Poidevin14mo ago
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,
])
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!
Want results from more Discord servers?
Add your server