diff --git a/README.md b/README.md index ffebb03..6ae9dd8 100644 --- a/README.md +++ b/README.md @@ -13,10 +13,10 @@ This is a package to monitor background jobs for FilamentPHP. It is inspired by Check your filamentPHP version before installing: -| Version | FilamentPHP | PHP | -|---------|-------------|-------------------------| -| 1.* | 2.* | 8.1.* | -| 2.* | 3.* | 8.1.* \| 8.2.* | +| Version | FilamentPHP | PHP | +| ------- | ----------- | -------------- | +| 1.* | 2.* | 8.1.* | +| 2.* | 3.* | 8.1.* \| 8.2.* | Install the package via composer: @@ -149,6 +149,33 @@ Then you can call your Job with the following code: } ``` +### Enabling navigation + + +````php + // AdminPanelProvider.php + ->plugins([ + // ... + FilamentJobsMonitorPlugin::make() + ->enableNavigation(), + ]) +```` + +Or you can use a closure to enable navigation only for specific users: + +```php + + // AdminPanelProvider.php + ->plugins([ + // ... + FilamentJobsMonitorPlugin::make() + ->enableNavigation( + fn () => auth()->user()->can('view_queue_job') || auth()->user()->can('view_any_queue_job)'), + ), + ]) +``` + + ## Changelog Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. diff --git a/src/FilamentJobsMonitorPlugin.php b/src/FilamentJobsMonitorPlugin.php index 0829e0e..0069a07 100644 --- a/src/FilamentJobsMonitorPlugin.php +++ b/src/FilamentJobsMonitorPlugin.php @@ -24,7 +24,7 @@ class FilamentJobsMonitorPlugin implements Plugin /** * The resource navigation status. */ - protected ?bool $navigation = null; + protected bool|Closure $navigation = true; /** * The resource cluster. @@ -247,15 +247,15 @@ public function navigationCountBadge(bool $navigationCountBadge = true): static */ public function shouldRegisterNavigation(): bool { - return $this->navigation ?? config('filament-jobs-monitor.resources.enabled'); + return $this->evaluate($this->navigation) === true ?? config('filament-jobs-monitor.resources.enabled'); } /** * Enable the resource navigation. */ - public function enableNavigation(bool $status = true): static + public function enableNavigation(bool|Closure $callback = true): static { - $this->navigation = $status; + $this->navigation = $callback; return $this; }