Appearance
Are you an LLM? You can read better optimized documentation at /guide/menus-and-links.md for this page in Markdown format
Menus & links
FilamentCraft builds a site's navigation from three places:
- The header's own items: links, dropdowns and category menus edited in the header. Together they are the site's Main menu.
- Menus your app already manages, through a
MenuSource. - The link picker in every link field, which searches pages, catalog categories and products, and any link source you register.
Menu sources
If your app already stores menus (a CMS table, a shop admin), bind a MenuSource and the editor offers them by name. The header gets a Menu to show setting; the footer's Menu block lists them next to Main menu (header).
php
use App\Models\Menu;
use FilamentCraft\Models\Site;
use FilamentCraft\Navigation\Contracts\MenuSource;
use FilamentCraft\Navigation\MenuItem;
final class AppMenus implements MenuSource
{
public function menus(Site $site): array
{
return Menu::query()->pluck('name', 'handle')->all();
}
public function items(Site $site, string $menu): array
{
return Menu::query()->where('handle', $menu)->first()?->items
->map(fn ($item) => new MenuItem(
$item->label,
$item->url,
$item->children->map(fn ($child) => new MenuItem($child->label, $child->url))->all(),
))
->all() ?? [];
}
}php
// AppServiceProvider::register()
$this->app->singleton(\FilamentCraft\Navigation\Contracts\MenuSource::class, AppMenus::class);- Items are read on every render, so menu changes appear without republishing. While a menu source is bound, the header skips the fragment cache.
- In the header, an item with children becomes a dropdown (desktop) and an expandable group (phone menu and the bottom bar's More sheet). Its own link becomes the dropdown's View all.
- In the footer, a menu whose items have children fills one column per item; items without children share one column under the block's heading.
- Links to draft pages are left out for visitors. Items without a label, and parents left with neither a link nor children, are dropped.
- A key the source no longer offers renders nothing in the footer, and the header falls back to its own items. A source that throws is reported and treated as empty, so a CMS outage never takes the page down.
The default binding, NullMenuSource, offers no menus; the setting then stays hidden.
Showing menu items to some visitors
Name the visitor groups once, then decide per request who sees what:
php
FilamentCraftPlugin::make()
->menuAudiences(['members' => 'Members', 'guests' => 'Guests'])
->menuItemVisibleUsing(
fn (MenuItem $item, Site $site, Request $request): bool => match ($item->audience) {
'members' => $request->user() !== null,
'guests' => $request->user() === null,
default => true,
},
);- Once
menuAudiences()has labels, header links, dropdowns and the header button get a Show to field. - The hook runs for every item, including items with no audience and the children of a dropdown or category, so you can also hide by link or label.
- A hook that throws is reported and the item stays visible.
- While a hook is set, the header and footer skip fragment caching.
- This hides a link, it is not access control. Protect the page itself with your own auth.
Link sources
The link picker suggests the site's pages, plus every catalog's categories and products. Add your own groups (blog posts, brands, events) with a LinkSource:
php
use App\Models\Post;
use FilamentCraft\Links\Contracts\LinkSource;
use FilamentCraft\Links\LinkTarget;
use FilamentCraft\Models\Site;
final class PostLinks implements LinkSource
{
public function key(): string { return 'posts'; }
public function label(): string { return 'Blog posts'; }
public function icon(): string { return 'heroicon-o-newspaper'; }
public function search(Site $site, string $term, int $limit): array
{
return Post::query()
->when($term !== '', fn ($query) => $query->where('title', 'like', "%{$term}%"))
->latest()
->limit($limit)
->get()
->map(fn (Post $post) => new LinkTarget($post->title, route('posts.show', $post), $post->published_at?->toFormattedDateString() ?? ''))
->all();
}
}php
FilamentCraftPlugin::make()->linkSources([PostLinks::class]);- An empty
$termasks for suggestions: return the few most useful targets. - The optional third
LinkTargetargument is the grey hint under the name. - The stored value is the target's URL, so pages built before your source existed keep working. When the field opens a saved link, it searches for the words in the URL's last segment to show the target's name again.
- A source that throws drops out of the results instead of breaking the picker.
Resolving links at render time
When the address of a record changes (/product/12/blue-mug became /product/blue-mug), the links stored in pages still hold the old one. Give FilamentCraft a resolver and it rewrites each link as it renders, with no redirect and no change to the stored content:
php
FilamentCraftPlugin::make()->resolveLinkUsing(
fn (string $href, Site $site): string => preg_replace('#^/product/\d+/#', '/product/', $href),
);- It runs for link settings, link lists, header and footer links and host menu items.
- An empty or unsafe result (
javascript:) and a throw keep the stored link; a throw is reported. - Keep it deterministic per site: the output is fragment-cached, and
filamentcraft:clear-cacheflushes it after you change the rule. - Links inside rich-text bodies are resolved too when they were inserted with the editor's link tool (see Linking from rich text); a plain
<a href>goes through your rule as written. - Not resolved: catalog category URLs, the link picker's preview and the sitemap.
Renaming a page
Links are stored as URLs, and when a page's address changes — its slug is edited in page settings, in the Templates resource or in code — FilamentCraft updates every link to it: in each page's draft and live version and in the header, footer and other regions. Each changed page gets a new version in its history, so anyone editing it with unsaved changes is told the page changed before they save over it. Links to the page's other languages follow too, whether the language is a path segment (/fr/about, /shop/fr/about) or a query (?locale=fr). Links keep their own #anchor and ?query, links to other sites are left alone, and renaming the homepage changes nothing because its address stays /. Links inside rich-text bodies follow too, and links to a page inserted with the link tool always show its current address. Menus served by your own MenuSource are not touched; keep Redirect the old URL to the new one ticked so those, and links from other websites, still arrive.
Code can do the same with PageLinkRewriter::rewrite($site, $from, $to). It is public API and covered by the breaking-change policy.
Linking from rich text
The link tool in a rich-text editor opens the same picker as link fields. Choosing a page, or a record from a link source, stores a reference next to the address (data-fc-ref="page:12"). At render time FilamentCraft looks the reference up and writes the target's current address into the link, so the link survives a rename without any stored change.
- A link to a page that is still a draft, was deleted, or belongs to another site is shown as plain text on the public site; the editor keeps the link. A record reference from a link source that no longer resolves keeps the stored address.
- Every address, resolved or not, goes through
resolveLinkUsing(). - Pages built before references existed keep their typed addresses, and a page rename rewrites those inside the body text.
To make your own source resolvable, implement ResolvesLinkReference as well as LinkSource. The reference is <source key>:<id>, so a source with the key posts receives the id 12 for posts:12:
php
use FilamentCraft\Links\Contracts\LinkSource;
use FilamentCraft\Links\Contracts\ResolvesLinkReference;
final class PostLinks implements LinkSource, ResolvesLinkReference
{
// key(), label(), icon() and search() as above
public function resolve(Site $site, string $id): ?string
{
$post = Post::query()->where('site_id', $site->getKey())->find($id);
return $post instanceof Post ? route('posts.show', $post) : null;
}
}Scope the lookup by $site as above, so a reference can never reach another tenant's record. Return null when the record is gone and the stored address is used instead.
References are resolved on every render, after the fragment cache, so a changed record address shows up without flushing anything. resolveLinkUsing() still applies to plain addresses inside the cached body, and to the resolved address of a reference.
Product and category links
Product and category links from your Storefront or Catalog are saved by slug, so renaming a slug breaks the reference and the link keeps its stored address. To follow renames, give your records a stable id and tell FilamentCraft how to find them:
php
use FilamentCraft\Commerce\Contracts\FindsRecordsById;
use FilamentCraft\Commerce\Contracts\Storefront;
final class ShopStorefront implements Storefront, FindsRecordsById
{
public function productById(string $id): ?ProductData
{
return $this->toData(Product::query()->find($id));
}
public function categoryById(string $id): ?CategoryData
{
return $this->categoryData(Category::query()->find($id));
}
// products() and the rest of Storefront build the data with `id: (string) $product->id`
}Set id: on ProductData and CategoryData. Links picked after that store the id and resolve through productById() / categoryById(); links saved earlier by slug keep working. Without FindsRecordsById, or for a record without an id, links use the slug as before. The same interface works on a custom Catalog.
Footer columns
The footer's Items list takes three kinds of block, in any order; each becomes a column:
| Block | Use it for |
|---|---|
| Link column | A heading and its own ordered links. |
| Menu | The main menu or a host menu, with an optional heading. |
| Text | A heading and a short text, such as an address or opening hours. |
Footers saved before columns existed stored one link block per link with a typed column name. They open in the editor as link columns and save in the new shape on their next edit; nothing changes for visitors. A footer whose links carry descriptions keeps the old links, since a column row has no room for one.