To create a new record in Filament Resource, users typically go to the List page and click the "Add New" button. But what if you want to add that link to the sidebar navigation? Let me show you how.
Here's our initial navigation menu. Would you like to add an "Add New Product" link below the "Products" item?
To do that, you must register a custom navigation item in the Panel Provider.
app/Providers/Filament/AdminPanelProvider.php:
use App\Filament\Resources\ProductResource;use Filament\Navigation\NavigationItem; // ... return $panel ->default() // ... more functions here ->navigationItems([ NavigationItem::make('Add New Product') ->url(fn () => ProductResource::getUrl('create')) ->icon('heroicon-o-plus') ->sort(3), ]);
Here's the result after that code:
Important parts:
getUrl()
, read more in the official docs
sort(3)
in this case assumes that the following UserResource has a property $navigationSort = 4
which positions it below the "Add New Product"Official Filament docs: Registering custom navigation items
A few of our Premium Examples: