Show a Modal with Custom Content, if necessary, after Create / Edit

Filament resources make it easy to create and edit records.
The Problem
Sometimes, after creating or editing a record, you might want to show a modal with custom content, like next steps for the user, or a warning message.
The Solution
We can achieve this by creating a custom widget for the modal, which is normally hidden. We may then trigger it from the Create and Edit pages of the resource, depending on our custom logic.
<?php
namespace App\Filament\Resources\PurchaseOrderResource\Pages;
use Illuminate\Support\Facades\Session;
use Filament\Resources\Pages\CreateRecord;
use App\Filament\Resources\PurchaseOrderResource;
use App\Filament\Resources\PurchaseOrderResource\Widgets\HighValuePurchaseOrder;
class CreatePurchaseOrder extends CreateRecord
{
protected static string $resource = PurchaseOrderResource::class;
protected function afterCreate(): void
{
if (HighValuePurchaseOrder::isNeededToShow($this->record)) {
Session::flash(HighValuePurchaseOrder::TRIGGER);
}
}
}
Add a confirmation modal before creating a record
Add a Confirmation Modal Before Creating a Record
Refreshing Relation Manager tab badges after updating records in Filament
Filament makes it easy to organize Relation Managers into tabs, complete with badges showing the record count. But we have a problem when we update records inside a Relation Manager, those badges won't refresh automatically.