F
Filamentβ€’8mo ago
myster

Sub navigation

How to use Sub navigation? Is it already available?
58 Replies
einnlleinhatt_
einnlleinhatt_β€’8mo ago
$navigationParentItems
Flo
Floβ€’8mo ago
Hello, I manage to add a custom page to the sub navigation by adding $navigationParentItems to the class of my Custom page. On the other hand, when I go to the view of this Custom page, the sub navigation does not appear. I hope to have been clear. Do you know how to customize the view for this?
Prodex
Prodexβ€’8mo ago
I'm confused as well. The sub navigation is not showing, and the docs are quite short for that topic...
Flo
Floβ€’8mo ago
Currently the sub navigation is displayed if custom pages extends "ManageRelatedRecords" but not for "Page"
BlackShadow
BlackShadowβ€’8mo ago
Im a little confused too, i added the following to my resource (basically copied the demo) but no nav is appearing.
public static function getRecordSubNavigation(Page $page): array
{
return $page->generateNavigationItems([
Pages\EditProfile::class,
Pages\ViewProfile::class,
ManageProfileAddresses::class,
]);
}
public static function getRecordSubNavigation(Page $page): array
{
return $page->generateNavigationItems([
Pages\EditProfile::class,
Pages\ViewProfile::class,
ManageProfileAddresses::class,
]);
}
Prodex
Prodexβ€’8mo ago
yes, same for me and "ManageRelatedRecords" doesn't make sense for me, as I want to add custom pages as well.
BlackShadow
BlackShadowβ€’8mo ago
Im not really using custom pages, just the normal view, edit and the new ManageRelatedRecords
Prodex
Prodexβ€’8mo ago
can anyone from the core team give us a hint?
Flo
Floβ€’8mo ago
@Prodex Does this appear for you on pages that have "ManageRelatedRecords"?
BlackShadow
BlackShadowβ€’8mo ago
Maybe we need to enable it first?
Prodex
Prodexβ€’8mo ago
the docs don't say anything about that
Dennis Koch
Dennis Kochβ€’8mo ago
@Dan Harrin Can you shed some light? There are multiple confused people here πŸ˜…
Dan Harrin
Dan Harrinβ€’8mo ago
sub navigation is not parent items someone tell me what youre trying to do
BlackShadow
BlackShadowβ€’8mo ago
Added this to my ProfileResource added a new ManageProfileAddresses page.
Flo
Floβ€’8mo ago
add sub navigation to Custom Page
Dan Harrin
Dan Harrinβ€’8mo ago
not specific enough please explain what youre actually trying to achieve
BlackShadow
BlackShadowβ€’8mo ago
My issue: Display the sub navigation
Dan Harrin
Dan Harrinβ€’8mo ago
the demo even has an example in the post resource
BlackShadow
BlackShadowβ€’8mo ago
I copied this, seems like im missing something still. πŸ€”
Dan Harrin
Dan Harrinβ€’8mo ago
so what is happening
Flo
Floβ€’8mo ago
class LogServer extends Page
{

protected static string $resource = ServerResource::class;

protected static string $view = 'filament.resources.server-resource.pages.log-server';

protected static ?string $title = 'Logs';

protected static ?string $navigationIcon = 'heroicon-s-book-open';

public Server $record;
}
class LogServer extends Page
{

protected static string $resource = ServerResource::class;

protected static string $view = 'filament.resources.server-resource.pages.log-server';

protected static ?string $title = 'Logs';

protected static ?string $navigationIcon = 'heroicon-s-book-open';

public Server $record;
}
Should I do something else? Configure the view?
BlackShadow
BlackShadowβ€’8mo ago
Nothing πŸ˜†
Dan Harrin
Dan Harrinβ€’8mo ago
have you defined getRecordSubNavigation() in the resource
BlackShadow
BlackShadowβ€’8mo ago
I think we are talking about 2 different issues here tbh.
Dan Harrin
Dan Harrinβ€’8mo ago
definitely.
BlackShadow
BlackShadowβ€’8mo ago
Yes.
Flo
Floβ€’8mo ago
yes :
public static function getRecordSubNavigation(Page $page): array
{
return $page->generateNavigationItems([
Pages\ListSitesServer::class,

Pages\LogServer::class,

]);
}
public static function getRecordSubNavigation(Page $page): array
{
return $page->generateNavigationItems([
Pages\ListSitesServer::class,

Pages\LogServer::class,

]);
}
Dan Harrin
Dan Harrinβ€’8mo ago
show the code for these pages
BlackShadow
BlackShadowβ€’8mo ago
I will let him go first, it will probably solve my issue too.
Dennis Koch
Dennis Kochβ€’8mo ago
One he posted above
Prodex
Prodexβ€’8mo ago
Like Flo said, I also copied the example from the docs and implemented my pages. But the sub nav doesn't show up, and we're trying to figure out why.
public static function getRecordSubNavigation(Page $page): array
{
return $page->generateNavigationItems([
Pages\Overview::class,
Pages\Projects::class,
]);
}
public static function getRecordSubNavigation(Page $page): array
{
return $page->generateNavigationItems([
Pages\Overview::class,
Pages\Projects::class,
]);
}
Is there anything, that needs to be done for the sub navigation to show up? (it's in the resource class btw, just like the docs said)
Dennis Koch
Dennis Kochβ€’8mo ago
Wait is it a resource or a custom page you put this on? Dan, do we support custom pages with subnavigation?
Dan Harrin
Dan Harrinβ€’8mo ago
all pages support sub navigation
Flo
Floβ€’8mo ago
(For me, it appears well on classic "view, edit..." pages but not on custom pages, and I think it's because of my view. But what to add there?)
Dan Harrin
Dan Harrinβ€’8mo ago
do any of you have custom themes maybe they need recompiling
BlackShadow
BlackShadowβ€’8mo ago
omg.. Thats it.. That solves my problem atleast....
Dan Harrin
Dan Harrinβ€’8mo ago
please recompile themes after every update
Dennis Koch
Dennis Kochβ€’8mo ago
Best to add this to composer scripts, too.
BlackShadow
BlackShadowβ€’8mo ago
Gonna do that right now πŸ‘€
Flo
Floβ€’8mo ago
For me, it still doesn't work. Should I add something here? log-server.blade.php
<x-filament-panels::page>

</x-filament-panels::page>
<x-filament-panels::page>

</x-filament-panels::page>
What exactly did you do? I use "npm run dev" in the background.
BlackShadow
BlackShadowβ€’8mo ago
I ran npm run build Refreshed the page and just like magic, it appeared!
Dennis Koch
Dennis Kochβ€’8mo ago
Yeah, probably something different here, as it works on the Resource.
Flo
Floβ€’8mo ago
Yes, anything that extends from "ManageRelatedRecords", "EditRecord", "ListRecords", "ViewRecord" works, but not if it extends from "Page" but why ?
Dan Harrin
Dan Harrinβ€’8mo ago
on the custom page
/**
* @return array<string, mixed>
*/
public function getSubNavigationParameters(): array
{
return [
'record' => $this->getRecord(),
];
}

public function getSubNavigation(): array
{
return static::getResource()::getRecordSubNavigation($this);
}
/**
* @return array<string, mixed>
*/
public function getSubNavigationParameters(): array
{
return [
'record' => $this->getRecord(),
];
}

public function getSubNavigation(): array
{
return static::getResource()::getRecordSubNavigation($this);
}
ListRecords doesnt do it, its just β€œrecord” pages just like default custom pages dont have a $record, they dont have record sub navigation either so you just have to point it towards the resource yourself
Prodex
Prodexβ€’8mo ago
yeah! That's it for me. Maybe this needs to be in the docs as well in the page section? I can add that later if you want.
Dan Harrin
Dan Harrinβ€’8mo ago
realised that using records on custom pages was severely underdocumented and also improved the experience of using InteractsWithRecord to handle the subnav you shouldnt need to define getSubNavigation() etc when this is released
Dennis Koch
Dennis Kochβ€’8mo ago
Damn, that was fast πŸ˜…
Dan Harrin
Dan Harrinβ€’8mo ago
just released v3.1.2 unofficially for this, since it should be a big improvement will be on packagist in 2 mins
Prodex
Prodexβ€’8mo ago
Nice!! Thank you so much Dan for your great effort all the time ❀️
Flo
Floβ€’8mo ago
Thank you Dan !
dev_ms
dev_msβ€’7mo ago
I'm using filament 3.1.8, and i have implemented everything written on the docs but not working. Could someone please help me Thanks
No description
hichem8377
hichem8377β€’7mo ago
protected static ?string $navigationParentItem = 'Hearing settings'; return Call to a member function keyBy() on null Please any one got the same issue
DrByte
DrByteβ€’7mo ago
Probably need to upgrade your Filament version.
ahinkle
ahinkleβ€’6mo ago
I ran into this. You may have permission mismatch here where the user can't access the parent item - but does have access to the child.
cvc
cvcβ€’5mo ago
Hi I tried this on a custom page - with and without commented code? https://gist.github.com/craigvc/f550679a599fd4dbb2721f24a50fbd7f I just want the navigation items to show up under settings - is this possible>?
Gist
Settings.php
GitHub Gist: instantly share code, notes, and snippets.
Dan Harrin
Dan Harrinβ€’5mo ago
clusters are superior to nav parent items, try those
cvc
cvcβ€’5mo ago
Hi yes ended up using them thanks!!!!