How do I redirect a user after login based on the panel they are allowed to view?

I have 2 panels:
class CpPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            ->default()
            ->id('cp')
            ->path('cp')
//...

class FrontendPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            ->id('frontend')
            ->path('')

I want to say, if you can view the Cp then redirect there, else redirect to the frontend. I have this in app/Http/Responses/LoginResponse.php
class LoginResponse implements LoginResponseContract
{
    public function toResponse($request)
    {
        return auth()->user()->canAccessPanel('TODO') ? 'TODO' : 'TODO';
    }
}
Solution
Gone with this, which is okay at the moment:
return Auth::user()->canAccessPanel(Filament::getPanel('cp'))
            ? redirect()->intended(route('filament.cp.pages.dashboard'))
            : redirect()->intended(route('home'));
Was this page helpful?