Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add is_lazy configuration #24

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading