Wiring New and Edit

The admin bar ships two empty hooks: a list of New items and an Edit resolver. The plugin renders the chrome; the clone tells those hooks where to go. Nothing in the plugin knows which Filament resource a public page belongs to — that mapping is the clone's job.

API

FilamentAdminBarPlugin exposes a fluent setter for each hook, applied in register():

FilamentAdminBarPlugin::make()
    ->newItems([
        ['label' => 'New Post', 'url' => fn () => route('filament.admin.resources.posts.create')],
        ['label' => 'New Doc',  'url' => fn () => route('filament.admin.resources.docs.create')],
    ])
    ->editUsing(fn (): ?string => $this->resolveEditUrl());

newItems accepts an array of ['label' => string, 'url' => Closure|string]. Each url is resolved lazily — closures run when the bar renders, so the clone can pick the right create route for the current page's model. editUsing takes a Closure(): ?string and returns the edit URL for the record on the current public page (or null to hide the Edit button). Both setters forward to the AdminBar facade, which is what the Blade component reads.

Wiring in the clone

Register the plugin in the panel provider, then resolve the edit URL from the public route's bound model:

->plugins([
    FilamentAdminBarPlugin::make()
        ->newItems([
            ['label' => 'New Post', 'url' => fn () => route('filament.admin.resources.posts.create')],
            ['label' => 'New Doc',  'url' => fn () => route('filament.admin.resources.docs.create')],
        ])
        ->editUsing(function (): ?string {
            $record = request()->route('post') ?? request()->route('doc');

            return $record
                ? route('filament.admin.resources.posts.edit', ['record' => $record])
                : null;
        }),
])

The resolver inspects the current request's route binding, maps the public model to its Filament resource, and returns the panel edit URL. On a list page with no bound record it returns null, so the bar shows New but not Edit.

flowchart LR
    A[Public page] --> B[AdminBar]
    B --> C{"newItems callback"}
    B --> D{"editUsing callback"}
    C --> E[Filament create route]
    D --> F[Filament edit route]

See also

Built by Qcentic