-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from kenepa/3.x
Filament v3 support
- Loading branch information
Showing
7 changed files
with
98 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,9 @@ saves or discards their changes. | |
|
||
## Installation | ||
|
||
> Version 1.x supports Filament v2. | ||
> Version 2.x supports Filament v3. | ||
You can install the package via composer: | ||
|
||
```bash | ||
|
@@ -29,6 +32,19 @@ Then run the installation command to publish and run migration(s) | |
php artisan resource-lock:install | ||
``` | ||
|
||
Register plugin with a panel | ||
```php | ||
use Kenepa\ResourceLock\ResourceLockPlugin; | ||
use Filament\Panel; | ||
|
||
public function panel(Panel $panel): Panel | ||
{ | ||
return $panel | ||
// ... | ||
->plugin(ResourceLockPlugin::make()); | ||
} | ||
``` | ||
|
||
You can publish run the config (optional) | ||
|
||
```bash | ||
|
@@ -139,7 +155,7 @@ the [Spatie Permissions package](https://github.com/spatie/laravel-permission). | |
|
||
'unlocker' => [ | ||
'limited_access' => true, | ||
'gate' => 'unlock-resource' | ||
'gate' => 'unlock' | ||
], | ||
``` | ||
|
||
|
@@ -148,12 +164,13 @@ Example | |
```php | ||
|
||
// Example using gates | ||
Gate::define('unlock-resource', function (User $user, Post $post) { | ||
// More info about gates: https://laravel.com/docs/authorization#writing-gates | ||
Gate::define('unlock', function (User $user, Post $post) { | ||
return $user->email === '[email protected]'; | ||
}); | ||
|
||
// Example using spatie permission package | ||
Permission::create(['name' => 'unlock-resource']); | ||
Permission::create(['name' => 'unlock']); | ||
``` | ||
|
||
### Using custom models | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Kenepa\ResourceLock; | ||
|
||
use Filament\Contracts\Plugin; | ||
use Filament\Panel; | ||
use Filament\Support\Facades\FilamentView; | ||
use Illuminate\Support\Facades\Blade; | ||
use Kenepa\ResourceLock\Resources\ResourceLockResource; | ||
use Livewire\Livewire; | ||
|
||
class ResourceLockPlugin implements Plugin | ||
{ | ||
public static function make(): static | ||
{ | ||
return app(static::class); | ||
} | ||
|
||
public function getId(): string | ||
{ | ||
return 'resource-lock'; | ||
} | ||
|
||
public function register(Panel $panel): void | ||
{ | ||
$panel | ||
->resources([ | ||
ResourceLockResource::class, | ||
]); | ||
} | ||
|
||
public function boot(Panel $panel): void | ||
{ | ||
Livewire::component('resource-lock-observer', Http\Livewire\ResourceLockObserver::class); | ||
|
||
FilamentView::registerRenderHook( | ||
'panels::body.end', | ||
fn (): string => Blade::render('@livewire(\'resource-lock-observer\')'), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters