Skip to content

Commit

Permalink
Add config option to redirect to the resource index instead of the vi…
Browse files Browse the repository at this point in the history
…ew (#179)

* add config option to redirect to the resource index instead of the resource view

* add config option to redirect to the resource index instead of the resource view

---------

Co-authored-by: Bianchi <[email protected]>
  • Loading branch information
bianchi and Bianchi authored May 6, 2024
1 parent 78bfefa commit a17fcf1
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
14 changes: 14 additions & 0 deletions config/filament-spatie-roles-permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@
'roles' => true,
],

/**
* Set to true to redirect to the resource index instead of the view
*/
'should_redirect_to_index' => [
'permissions' => [
'after_create' => false,
'after_edit' => false
],
'roles' => [
'after_create' => false,
'after_edit' => false
],
],

/*
* If you want to place the Resource in a Cluster, then set the required Cluster class.
* Eg. \App\Filament\Clusters\Cluster::class
Expand Down
10 changes: 10 additions & 0 deletions src/Resources/PermissionResource/Pages/CreatePermission.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,19 @@
namespace Althinect\FilamentSpatieRolesPermissions\Resources\PermissionResource\Pages;

use Althinect\FilamentSpatieRolesPermissions\Resources\PermissionResource;
use Althinect\FilamentSpatieRolesPermissions\Resources\RoleResource;
use Filament\Resources\Pages\CreateRecord;

class CreatePermission extends CreateRecord
{
protected static string $resource = PermissionResource::class;

protected function getRedirectUrl(): string
{
$resource = static::getResource();

return config('filament-spatie-roles-permissions.should_redirect_to_index.permissions.after_create', false)
? $resource::getUrl('index')
: parent::getRedirectUrl();
}
}
9 changes: 9 additions & 0 deletions src/Resources/PermissionResource/Pages/EditPermission.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,13 @@
class EditPermission extends EditRecord
{
protected static string $resource = PermissionResource::class;

protected function getRedirectUrl(): ?string
{
$resource = static::getResource();

return config('filament-spatie-roles-permissions.should_redirect_to_index.permissions.after_edit', false)
? $resource::getUrl('index')
: parent::getRedirectUrl();
}
}
9 changes: 9 additions & 0 deletions src/Resources/RoleResource/Pages/CreateRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,13 @@
class CreateRole extends CreateRecord
{
protected static string $resource = RoleResource::class;

protected function getRedirectUrl(): string
{
$resource = static::getResource();

return config('filament-spatie-roles-permissions.should_redirect_to_index.roles.after_create', false)
? $resource::getUrl('index')
: parent::getRedirectUrl();
}
}
9 changes: 9 additions & 0 deletions src/Resources/RoleResource/Pages/EditRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,13 @@ public function getHeaderActions(): array
DeleteAction::make(),
];
}

protected function getRedirectUrl(): ?string
{
$resource = static::getResource();

return config('filament-spatie-roles-permissions.should_redirect_to_index.roles.after_create', false)
? $resource::getUrl('index')
: parent::getRedirectUrl();
}
}

0 comments on commit a17fcf1

Please sign in to comment.