From 8bb969fef3de3f5826fcbf62c3b48ec2c2260635 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9ia=20Bohner?= Date: Sun, 24 Sep 2023 18:38:56 -0300 Subject: [PATCH] Add updateAuditsRelationManager event listener --- README.md | 13 +++++++++++++ src/RelationManagers/AuditsRelationManager.php | 2 ++ 2 files changed, 15 insertions(+) diff --git a/README.md b/README.md index 9956544..3c098a2 100644 --- a/README.md +++ b/README.md @@ -145,3 +145,16 @@ public function auditRestored() // your code } ``` + +### Event listener + +The audits relation manager listen to the `updateAuditsRelationManager` event to refresh the audits table. + +So you can dispatch this event in the Edit page of your resource (e.g.: in a edit page of a `PostResource` -> `app/Filament/Resources/PostResource/Pages/EditPost.php`) when the form is updated: + +```php +public function updated() +{ + $this->dispatch('updateAuditsRelationManager'); +} +``` diff --git a/src/RelationManagers/AuditsRelationManager.php b/src/RelationManagers/AuditsRelationManager.php index 943d50d..e320c32 100644 --- a/src/RelationManagers/AuditsRelationManager.php +++ b/src/RelationManagers/AuditsRelationManager.php @@ -18,6 +18,8 @@ class AuditsRelationManager extends RelationManager protected static ?string $recordTitleAttribute = 'id'; + protected $listeners = ['updateAuditsRelationManager' => '$refresh']; + public static function canViewForRecord(Model $ownerRecord, string $pageClass): bool { return auth()->user()->can('audit', $ownerRecord);