Skip to content

Commit

Permalink
Merge pull request #17 from TappNetwork/add_update_relation_manager_e…
Browse files Browse the repository at this point in the history
…vent_listener

Add updateAuditsRelationManager event listener
  • Loading branch information
andreia authored Sep 24, 2023
2 parents 990e46d + 8bb969f commit f294cb4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
```
2 changes: 2 additions & 0 deletions src/RelationManagers/AuditsRelationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f294cb4

Please sign in to comment.