Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

anonymouse703's avatar

How to avoid widget hidden when selecting Date filter?

I have this Merchant Dashboard (widgets) if the route is dashboard only MerchantAdmin can view but on the StorePerformance page SuperAdmin, Admin and MerchantAdmin can view

    public static function canView(): bool
    {

        $user = auth()->user();

        if(request()->routeIs('filament.admin.pages.dashboard')){
            return $user->role === Role::MerchantAdmin;
        }elseif(request()->routeIs('filament.admin.pages.store-performance')){
            return in_array($user->role, [
                Role::SuperAdmin,
                Role::Admin,
                Role::MerchantAdmin,
            ]);
        }

        return false;
    }
0 likes
3 replies
tisuchi's avatar

@anonymouse703 So what is the issue? Isn't that working? It seems correct to me!

However, I suggest this clean approach for you:


public static function canView(): bool
{
    $user = auth()->user();
    $role = $user?->role;

    if (! $role) {
        return false;
    }

    if (request()->routeIs('filament.admin.pages.dashboard')) {
        return $role === Role::MerchantAdmin;
    }

    if (request()->routeIs('filament.admin.pages.store-performance')) {
        return in_array($role, [
            Role::SuperAdmin,
            Role::Admin,
            Role::MerchantAdmin,
        ], true);
    }

    return false;
}
anonymouse703's avatar

@tisuchi the problem is this routeIs() since when you click the filter action then the request is through ajax (component) and not the route anymore

page code

tisuchi's avatar

@anonymouse703 I see, how about this approach?

public static function canView(): bool
{
    $user = auth()->user();
    $role = $user?->role;

    if (! $role) {
        return false;
    }

    $page = filament()->getCurrentPage();

    if ($page instanceof \App\Filament\Admin\Pages\Dashboard) {
        return $role === Role::MerchantAdmin;
    }

    if ($page instanceof \App\Filament\Admin\Pages\StorePerformance) {
        return in_array($role, [
            Role::SuperAdmin,
            Role::Admin,
            Role::MerchantAdmin,
        ], true);
    }

    return false;
}

Please or to participate in this conversation.