© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•14mo ago•
3 replies
ikbentomas

Show navigation badge in sub navigation with count of relationship

I've made pages for a resource and listed those pages as sub navigation items.
In this particular case I have 'notes' as child resource of the parent resource 'Server'
My goal is to show the amount of related notes and an indicator of important notes in the sub navigation.

I've made a working version like this in the Notes Page.
class Notes extends Page
{
    public static function getNavigationBadge(): string
    {
        $record = request('record');

        return Note::query()->where('server_id', $record->id)->count();
    }
}
class Notes extends Page
{
    public static function getNavigationBadge(): string
    {
        $record = request('record');

        return Note::query()->where('server_id', $record->id)->count();
    }
}


But the main disadvantages of this approach are the tests, I'm unable to mock the request class.
And the value of
$record
$record
is sometimes the Server model and on the View page the value becomes just the ID of the model.
I would prefer a solution like this method on the parent resource, where
Page $page
Page $page
is available.

class ServerResource extends Resource
{
    public static function getRecordSubNavigation(Page $page): array
    {
        $items = array_filter([
            // doing some logic with the $page->record 
        ]);

        return $page->generateNavigationItems($items);
    }
}
class ServerResource extends Resource
{
    public static function getRecordSubNavigation(Page $page): array
    {
        $items = array_filter([
            // doing some logic with the $page->record 
        ]);

        return $page->generateNavigationItems($items);
    }
}
Screenshot_2025-01-02_at_07.36.08.png
Solution
Can't you just do something like this to test?
$this->get(Notes::getUrl([..params..]))
$this->get(Notes::getUrl([..params..]))
?
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Dynamic Badge Count on Sub Navigation Relation Page
FilamentFFilament / ❓┊help
2y ago
Badge on sub-navigation
FilamentFFilament / ❓┊help
3y ago
add navigation badge to relationship managers
FilamentFFilament / ❓┊help
3y ago
How to show Count relationship in table?
FilamentFFilament / ❓┊help
3y ago