Skip to content

Commit

Permalink
updated doc
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenjude committed Sep 12, 2024
1 parent 0c53061 commit ba9b3b3
Showing 1 changed file with 63 additions and 86 deletions.
149 changes: 63 additions & 86 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
![](https://raw.githubusercontent.com/stephenjude/filament-debugger/main/art/banner.jpg)

# Filament Debugger

[![Latest Version on Packagist](https://img.shields.io/packagist/v/stephenjude/filament-debugger.svg?style=flat-square)](https://packagist.org/packages/stephenjude/filament-debugger)
Expand All @@ -9,7 +7,7 @@

Easily add Laravel Telescope and Horizon to Filament admin panel.

![](https://raw.githubusercontent.com/stephenjude/filament-debugger/main/art/screen1.png)
![](./art/screen1.png)

## Installation

Expand All @@ -19,62 +17,83 @@ You can install the package via composer:
composer require stephenjude/filament-debugger
```

Run the setup command using

```bash
php artisan filament-debugger:install
```

This is the contents of the published config file:

## Usages
```php
return [
'debuggers' => [
'horizon',
'telescope'
],

'authorization' => false,

'permissions' => [
'horizon' => 'horizon.view',
'telescope' => 'telescope.view',
],
];
public function panel(Panel $panel): Panel
{
use Stephenjude\FilamentDebugger\DebuggerPlugin;

return $panel
->plugin(
DebuggerPlugin::make()
);
}
```

Add the plugin to your panel plugins array
### Custom Role/Permission
You can authorize the plugin for users with a specific role/permission:

```php
$panel
->plugins([
DebuggerPlugin::make(),
]);
```
use Stephenjude\FilamentDebugger\DebuggerPlugin;

$panel->plugin(
DebuggerPlugin::make()->authorize(
condition: fn()=>auth()->user()->can('view.debuggers')
)
);
```

## Debuggers
This package comes with first party Laravel packages for development and monitoring your Laravel application.
### Custom Navigation Group
You can customize the navigation group:

### Laravel Telescope
Telescope provides insight into the requests coming into your application, exceptions, log entries, database queries, queued jobs, mail, notifications, cache operations, scheduled tasks, variable dumps, and more. [Documentation](https://laravel.com/docs/9.x/telescope).
```php
use Stephenjude\FilamentDebugger\DebuggerPlugin;

### Laravel Horizon
Horizon allows you to easily monitor key metrics of your queue system such as job throughput, runtime, and job failures. [Documentation](https://laravel.com/docs/9.x/horizon).
## Usage
Now you can view the installed debuggers when you log in into your filament admin panel.
$panel->plugin(
DebuggerPlugin::make()->groupNavigation(
condition: true,
label: 'Debugger'
)
);
```

### Custom Navigation Items
You can customize the navigation items:

## Gates & Authorization
When using filament debuggers (Horizon & Telescope) in production environment, we need to make sure that they are accessible to the authorized filament admin user.
```php
use Stephenjude\FilamentDebugger\DebuggerPlugin;

$panel->plugin(
DebuggerPlugin::make()
->horizonNavigation(
condition: fn () => auth()->user()->can('view.horizon'),
label: 'Horizon',
icon: 'heroicon-o-globe-europe-africaglobe-europe-africa',
url: url('horizon'),
openInNewTab: fn () => true
)
->telescopeNavigation(
condition: fn()=> auth()->user()->can('view.telescope'),
label: 'Telescope',
icon: 'heroicon-o-sparkles',
url: url('telescope'),
openInNewTab: fn () => true
)
->pulseNavigation(
condition: fn () => auth()->user()->can('view.pulse'),
label: 'Pulse',
icon: 'heroicon-o-bolt',
url: url('pulse'),
openInNewTab: fn () => true
)
);
```

To achive this, we need to use filament default authorization guard and the permissions provided in this package by overidding the `gate()` and `authorization()` methods inside the HorizonServiceProvider and TelescopeServiceProvider respectively.
## Gates & Authorization
When using filament debuggers (Horizon, Telescope & Pulse) in production environment, we need to make sure that they are accessible to the authorized filament admin user.

### Navigation Access
We need to set authorization to `true` inside the filament debugger config if we want to make it visible to only users with correct access in the admin panel navigation.
To achive this, we need to use filament default authorization guard and the permissions provided in this package by overidding the `gate()` and `authorization()` methods inside the HorizonServiceProvider, TelescopeServiceProvider and PulseServiceProvider respectively.

### Update HorizonServiceProvider.php
```php
protected function gate()
{
Expand All @@ -92,48 +111,6 @@ protected function authorization()

```

### Update TelescopeServiceProvider.php
```php
protected function gate()
{
Gate::define('viewTelescope', function ($user) {
return $user->can(config('filament-debugger.permissions.telescope'));
});
}

protected function authorization()
{
Auth::setDefaultDriver(config('filament.auth.guard'));

parent::authorization();
}

```

## Creating Permissions
To make use of the permissions configured in this package we need a permission package like [Laravel Permissions](https://github.com/spatie/laravel-permission) or [Bouncer](https://github.com/JosephSilber/bouncer) which usually comes with the `Permission` Model. USe what works for you.

The permissions we need to create is already defined inside the filament debugger config file.

Here is an example using the Spatie Permission Package:

```php
use Spatie\Permission\Models\Permission;

collect(config('filament-debugger.permissions'))
->map(fn($permission) => Permission::firstOrCreate([
'name' => $permission,
'guard_name' => config('filament.auth.guard'),
]));
```
You can also use your already created permission by updating the permission configuration:
```php
'permissions' => [
'horizon' => 'your horizon permission name',
'telescope' => 'your telescope permission name',
],
```

#### Screenshots:


Expand Down

0 comments on commit ba9b3b3

Please sign in to comment.