Search by

brewless / filament

Jaspur

Publish Filament records to the Brewless edge when they are saved, with actions, a status widget and a redirects resource.

Package info

github.com/brewless/filament

Homepage

pkg:composer/brewless/filament

Statistics

Installs: 11

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.3.1 2026-11-30 21:45 UTC

This package is auto-updated.

Last update: 2026-11-30 21:46:13 UTC


README

A Filament 5 plugin for publishing to the Brewless edge. When a record is saved or deleted in Filament, its pages are published to the edge, and the old address of a changed slug is emptied too. It also adds a "Publish to edge" action, a status widget for the dashboard and, if you want it, a resource for the redirects at the edge.

It uses Edge from brewless/laravel. Brewless fetches each page from your application and keeps it at bunny.net, so a visitor gets it without waking the container.

Requirements

  • PHP 8.3 or newer
  • Laravel 12 or 13
  • Filament 5
  • brewless/laravel 1.14 or newer
  • edge: { publish: true } for the environment in brewless.yml. Brewless then gives the containers BREWLESS_EDGE_KEY. Without it the plugin does nothing: saves work as before, the actions are hidden and the widget says how to switch it on.
  • A real queue. A publish is sent from a queued job; on the sync connection the job runs inside the save.

Install

composer require brewless/filament

Register the plugin on a panel:

use Brewless\Filament\BrewlessEdgePlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        // ...
        ->plugin(BrewlessEdgePlugin::make());
}

The options and their defaults:

BrewlessEdgePlugin::make()
    ->autoPublish(true)          // publish on create, edit and delete in this panel
    ->statusWidget(true)         // the status widget on the dashboard
    ->redirectsResource(false);  // the redirects resource (needs a migration, see below)

Public pages stay at the edge

Filament 5 puts its notification mailbox on every route of an application, not only on the panel's, and on every page that starts a session with a CSRF token and a mailbox address. A public page then answers with a session cookie, and the edge keeps no page with a cookie: with Filament installed, no public page would come from the edge.

This package therefore leaves the mailbox out where no notification can be waiting: a GET or HEAD from a visitor without a session cookie, on a route outside every Filament panel, that is not a Livewire request. Panel pages, form posts, Livewire requests and visitors who already have a session get Filament's middleware as before. To turn it off:

// config/brewless-filament.php, or config(['brewless-filament.public_pages_without_session' => false])
'public_pages_without_session' => false,

Say which pages a record shows on

A model takes part by implementing Brewless\Filament\Contracts\HasEdgeUrls. edgeUrls() gives every address the record shows on: its own page, the lists it is in, the sitemap, the feed. A path starting with / is published on every hostname of the environment; a full https:// URL only on that hostname. null is skipped and the query is left off.

use Brewless\Filament\Contracts\HasEdgeUrls;

final class Post extends Model implements HasEdgeUrls
{
    public function edgeUrls(): array
    {
        return [
            route('posts.show', $this),       // /blog/{slug}
            route('posts.index'),             // /blog
            $this->category ? route('categories.show', $this->category) : null,
            '/',
            '/sitemap.xml',
        ];
    }
}

On a change the plugin publishes the addresses from before and after the change. When the slug goes from hello to hello-world, both /blog/hello and /blog/hello-world are published: the new page is put at the edge, and the old address is emptied there, so it gives what the application now answers (a 404 or your redirect) instead of an old copy. The same goes for a record that moves to another category. A deleted record is published too, for the same reason.

A model without HasEdgeUrls is never published.

When it publishes

Where in Filament Addresses Reason sent to Brewless
Create page after filament.created
Edit page before and after filament.updated
CreateAction, ReplicateAction after filament.created
EditAction before and after filament.updated
DeleteAction, ForceDeleteAction before filament.deleted
DeleteBulkAction, ForceDeleteBulkAction before, for every selected record filament.deleted
RestoreAction, RestoreBulkAction after filament.restored

The actions count wherever they are: a table, a page header, a modal or a relation manager. After a publish Filament shows "Sent to the edge", only when the environment has the edge key.

A save never waits on Brewless and never fails because of it. Edge::publish() puts the addresses in a queued job. Inside a database transaction (Filament's, when the panel uses ->databaseTransactions(), or your own) the job is queued only once it commits, and a save that is rolled back publishes nothing. If Brewless is away, the job tries again later (after 10 seconds, a minute, 5 and 15 minutes). If anything in the plugin throws, for example your edgeUrls(), the error is reported and the save goes on.

Not covered: a change made outside Filament (a command, a job, an import), EditRecord::saveFormComponentOnly(), and bulk actions of your own. Call Edge::publish($record->edgeUrls()) there yourself.

Why these hooks

Filament 5 has three ways in that need no code on each resource. The plugin uses the ones Filament itself announces, and only for Filament:

  • RecordCreated and RecordUpdated. Filament dispatches these events from the create and edit pages after the save, inside its transaction. They give the record after the change.
  • ActionCalling and ActionCalled. Filament dispatches these around every action. ActionCalling comes before the action runs, while a record that is about to be changed or deleted is still as it was: that is where the "before" addresses of an edit or delete are taken, also for every selected record of a bulk delete. ActionCalled comes after, and publishes. An action on a resource page also leads to RecordCreated or RecordUpdated; the plugin publishes such a record once, not twice.
  • Livewire's call hook on an edit page. On every request Livewire loads the record fresh from the database, before it calls the page's method. The hook takes the addresses there, so they are those of the record as it was loaded, before the save changed it. This also catches a changed relation, such as another category, which a model's getOriginal() would not.

The other options were weaker. A trait on each page (PublishesToEdge) works, but needs code on every resource and is easy to forget. Eloquent model events (saved, deleted) fire for every change, also outside Filament, and cannot see a bulk delete done by a query; limiting them to Filament requests means guessing from the request.

The actions

use Brewless\Filament\Actions\PublishToEdgeAction;
use Brewless\Filament\Actions\PublishToEdgeBulkAction;

// An edit or view page
protected function getHeaderActions(): array
{
    return [PublishToEdgeAction::make()];
}

// A table
->recordActions([PublishToEdgeAction::make()])
->toolbarActions([PublishToEdgeBulkAction::make()])

Both publish now with Edge::publishNow() (in parts of 100, which is what one request takes) and show the id of each operation, or what went wrong: publishing not available (no key, or switched off for the environment), Brewless refused, or Brewless could not be reached. Both are hidden without the edge key; the single action also for a record without HasEdgeUrls. The reason sent is filament.manual.

The status widget

EdgeStatusWidget is on the dashboard by default. It shows:

  • whether publishing is on;
  • the last publish: when, and how many addresses were published, removed, not kept and failed;
  • the number of redirects and of addresses still waiting;
  • the 10 most recent addresses, each with its outcome.

It reads Edge::status() (GET /api/runtime/edge/status) and looks again every 60 seconds. brewless/laravel keeps the answer for 30 seconds, so a dashboard left open asks Brewless at most once a minute. Without the edge key it shows one line on how to switch publishing on.

To put it somewhere else, switch it off on the plugin and add Brewless\Filament\Widgets\EdgeStatusWidget to the page you want.

The redirects resource

For an application that keeps its redirects in Filament. If you already have them somewhere (Route::redirect, a table of your own, a CSV file), keep them there and send them with php artisan brewless:redirects from brewless/laravel; a second list would only get out of step.

php artisan vendor:publish --tag=brewless-filament-migrations
php artisan migrate
BrewlessEdgePlugin::make()->redirectsResource()

A redirect has a from path (end it with * for a prefix rule), a to path or https:// address, and a status of 301, 302, 307 or 308. The resource refuses what Brewless refuses:

  • from must start with / (not //), have a * only at the end, and have no query or spaces;
  • from cannot be under /_ops, /.well-known or /_brewless;
  • to must be a path starting with / or an https:// address. Brewless also takes http://, but brewless/laravel does not send it, so it is refused here;
  • at most 10,000 redirects.

After every change the whole set is sent to the edge from a queued job (SyncEdgeRedirects). The job reads the table when it runs, not when it was queued, so the edge always gets the latest set, also when two jobs run out of order. While one job waits in the queue no second one is queued, so a bulk delete of 50 redirects sends the set once or twice, not 50 times.

To send the set by hand, after an import or as a release command:

php artisan brewless-filament:sync-redirects

Testing

Use Edge::fake() from brewless/laravel. Nothing is queued or sent:

use Brewless\Laravel\Facades\Edge;

test('a changed slug publishes the old and the new address', function () {
    $post = Post::factory()->create(['slug' => 'hello']);
    $edge = Edge::fake();

    Livewire::test(EditPost::class, ['record' => $post->getRouteKey()])
        ->fillForm(['slug' => 'hello-world'])
        ->call('save');

    $edge->assertPublished(['/blog/hello', '/blog/hello-world']);
});

For the widget, give the fake a status:

Edge::fake()->withStatus(['publish' => true, 'redirects' => 3, 'recent' => []]);

Without Edge::fake() and without BREWLESS_EDGE_KEY nothing is sent either, so existing tests keep working.

For AI agents

The package ships a Laravel Boost guideline and a brewless-filament skill in resources/boost/. Run php artisan boost:install (or boost:update) in your application and your coding agent gets them, next to the ones of brewless/laravel.

Translations

Every text is in lang/<locale>/edge.php: English is the default, Dutch comes with it. The package follows the application's locale (app()->getLocale()), so a panel in Dutch shows Dutch.

To change a text, or to add a language, publish the files and edit or copy them:

php artisan vendor:publish --tag=brewless-filament-translations
# lang/vendor/brewless-filament/en/edge.php, nl/edge.php; add de/edge.php for German

A test keeps English and Dutch at the same keys.

Development

composer install
npm ci            # only for Pint's Blade formatting
vendor/bin/pest
vendor/bin/pint

Licence

MIT. See LICENSE.