Skip to content

Commit

Permalink
Merge pull request #24 from TappNetwork/add_config_for_is_lazy
Browse files Browse the repository at this point in the history
Add is_lazy configuration
  • Loading branch information
andreia authored Feb 5, 2024
2 parents 14d77b5 + 00201a4 commit 82cf522
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ return [
'column' => 'created_at',
'direction' => 'desc',
],

'is_lazy' => true,

'audits_extend' => [
// 'url' => [
Expand Down Expand Up @@ -153,8 +155,13 @@ The audits relation manager listen to the `updateAuditsRelationManager` event to
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()
protected function afterSave(): void
{
$this->dispatch('updateAuditsRelationManager');
}
```

> [!WARNING]
> When dispaching this event, set the [is_lazy](https://filamentphp.com/docs/3.x/panels/resources/relation-managers#disabling-lazy-loading) configuration to `false`, on `filament-auditing.php`
> config file, to avoid this exception: "Typed property Filament\Resources\RelationManagers\RelationManager::$table
> must not be accessed before initialization"
2 changes: 2 additions & 0 deletions config/filament-auditing.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
'direction' => 'desc',
],

'is_lazy' => true,

/**
* Extending Columns
* --------------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions src/RelationManagers/AuditsRelationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class AuditsRelationManager extends RelationManager

protected $listeners = ['updateAuditsRelationManager' => '$refresh'];

public static function isLazy(): bool
{
return config('filament-auditing.is_lazy');
}

public static function canViewForRecord(Model $ownerRecord, string $pageClass): bool
{
return Filament::auth()->user()->can('audit', $ownerRecord);
Expand Down

0 comments on commit 82cf522

Please sign in to comment.