How to Implement Conditional Sub-Navigation in Filament v4 Resources
James Manager
When building complex admin panels with Filament v4, navigation plays a huge role in user experience. You might want quick-access tabs between related pages — for example, when editing or processing a record — but showing those tabs everywhere can make your interface cluttered and confusing.
You can easily add a method to your Filament resources so that tabs only appear on specific pages.Â
The Problem
Let’s imagine you have a Lead resource with multiple pages:
- List Leads (index)
- View Lead (view)
- Edit Lead (edit)
- Pre-Qualify Lead (pre-qualify)
- Move to Compliance (move-to-compliance)
You would like sub-navigation tabs for easy switching between Edit, Pre-Qualify, and Move to Compliance pages. But you don’t want these tabs cluttering up your View pages.
By default, Filament shows sub-navigation on all record pages once getRecordSubNavigation() is defined in your resource — which can quickly lead to a messy UI.
The Solution
To fix this, you can call the `getSubNavigation()` method in the page you don't want the sub-navigation to appear and return an empty array.
class ViewLead extends ViewRecord
{
protected static string $resource = LeadResource::class;
public function getSubNavigation(): array
{
return [];
}
}This gives you precise control, clear intent in your code, and flexibility to add or remove navigation per page.
Tags
Share this article
Related Articles
Filament v4 is Coming: Here are Somethings You Need to Know
Filament v4 is coming! Discover its powerful new features, performance boosts, and enhanced flexibility to take your Laravel apps to the next level. 🚀
How to Make a Filament Table Column Both Clickable and Copyable
Make Filament TextColumn both clickable and copyable — link on text, copy on icon — with a simple AlpineJS hack.
New Features in TweakPHP 0.7.0 Release
Discover TweakPHP 0.7.0’s custom loaders and improved cross-platform support, boosting PHP development efficiency and flexibility.