-
Notifications
You must be signed in to change notification settings - Fork 56
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 canyongbs/feature/roles-and-permissions-r…
…esources [Feature] Roles and Permissions Resources
- Loading branch information
Showing
19 changed files
with
566 additions
and
25 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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources; | ||
|
||
use Filament\Forms; | ||
use Filament\Tables; | ||
use Filament\Forms\Form; | ||
use App\Models\Permission; | ||
use Filament\Tables\Table; | ||
use Filament\Resources\Resource; | ||
use App\Filament\Resources\PermissionResource\Pages; | ||
use App\Filament\Resources\PermissionResource\RelationManagers\RolesRelationManager; | ||
|
||
class PermissionResource extends Resource | ||
{ | ||
protected static ?string $model = Permission::class; | ||
|
||
protected static ?string $navigationIcon = 'heroicon-o-key'; | ||
|
||
protected static ?string $navigationGroup = 'Administration'; | ||
|
||
protected static ?int $navigationSort = 2; | ||
|
||
public static function form(Form $form): Form | ||
{ | ||
return $form | ||
->schema([ | ||
Forms\Components\TextInput::make('name') | ||
->required() | ||
->maxLength(125), | ||
Forms\Components\TextInput::make('guard_name') | ||
->required() | ||
->maxLength(125), | ||
]); | ||
} | ||
|
||
public static function table(Table $table): Table | ||
{ | ||
return $table | ||
->columns([ | ||
Tables\Columns\TextColumn::make('name') | ||
->searchable(), | ||
Tables\Columns\TextColumn::make('guard_name') | ||
->searchable(), | ||
Tables\Columns\TextColumn::make('created_at') | ||
->dateTime() | ||
->sortable() | ||
->toggleable(isToggledHiddenByDefault: true), | ||
Tables\Columns\TextColumn::make('updated_at') | ||
->dateTime() | ||
->sortable() | ||
->toggleable(isToggledHiddenByDefault: true), | ||
]) | ||
->filters([ | ||
]) | ||
->actions([ | ||
Tables\Actions\ViewAction::make(), | ||
]); | ||
} | ||
|
||
public static function getRelations(): array | ||
{ | ||
return [ | ||
RolesRelationManager::class, | ||
]; | ||
} | ||
|
||
public static function getPages(): array | ||
{ | ||
return [ | ||
'index' => Pages\ListPermissions::route('/'), | ||
'view' => Pages\ViewPermission::route('/{record}'), | ||
]; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
app/Filament/Resources/PermissionResource/Pages/ListPermissions.php
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,28 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\PermissionResource\Pages; | ||
|
||
use Filament\Resources\Pages\ListRecords; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use Filament\Resources\Pages\ListRecords\Tab; | ||
use App\Filament\Resources\PermissionResource; | ||
|
||
class ListPermissions extends ListRecords | ||
{ | ||
protected static string $resource = PermissionResource::class; | ||
|
||
public function getTabs(): array | ||
{ | ||
return [ | ||
'web' => Tab::make('Web') | ||
->modifyQueryUsing(fn (Builder $query) => $query->web()), | ||
'api' => Tab::make('Api') | ||
->modifyQueryUsing(fn (Builder $query) => $query->api()), | ||
]; | ||
} | ||
|
||
protected function getHeaderActions(): array | ||
{ | ||
return []; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
app/Filament/Resources/PermissionResource/Pages/ViewPermission.php
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,17 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\PermissionResource\Pages; | ||
|
||
use Filament\Resources\Pages\ViewRecord; | ||
use App\Filament\Resources\PermissionResource; | ||
|
||
class ViewPermission extends ViewRecord | ||
{ | ||
protected static string $resource = PermissionResource::class; | ||
|
||
protected function getHeaderActions(): array | ||
{ | ||
return [ | ||
]; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
app/Filament/Resources/PermissionResource/RelationManagers/RolesRelationManager.php
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,48 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\PermissionResource\RelationManagers; | ||
|
||
use Filament\Forms; | ||
use Filament\Tables; | ||
use Filament\Forms\Form; | ||
use Filament\Tables\Table; | ||
use Filament\Resources\RelationManagers\RelationManager; | ||
|
||
class RolesRelationManager extends RelationManager | ||
{ | ||
protected static string $relationship = 'roles'; | ||
|
||
protected static ?string $recordTitleAttribute = 'name'; | ||
|
||
public function form(Form $form): Form | ||
{ | ||
return $form | ||
->schema([ | ||
Forms\Components\TextInput::make('name') | ||
->required() | ||
->maxLength(255), | ||
]); | ||
} | ||
|
||
public function table(Table $table): Table | ||
{ | ||
return $table | ||
->columns([ | ||
Tables\Columns\TextColumn::make('name'), | ||
]) | ||
->filters([ | ||
]) | ||
->headerActions([ | ||
Tables\Actions\CreateAction::make(), | ||
]) | ||
->actions([ | ||
Tables\Actions\EditAction::make(), | ||
Tables\Actions\DeleteAction::make(), | ||
]) | ||
->bulkActions([ | ||
Tables\Actions\BulkActionGroup::make([ | ||
Tables\Actions\DeleteBulkAction::make(), | ||
]), | ||
]); | ||
} | ||
} |
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,84 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources; | ||
|
||
use Filament\Forms; | ||
use App\Models\Role; | ||
use Filament\Tables; | ||
use Filament\Forms\Form; | ||
use Filament\Tables\Table; | ||
use Filament\Resources\Resource; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use App\Filament\Resources\RoleResource\Pages; | ||
use App\Filament\Resources\RoleResource\RelationManagers\PermissionsRelationManager; | ||
|
||
class RoleResource extends Resource | ||
{ | ||
protected static ?string $model = Role::class; | ||
|
||
protected static ?string $navigationIcon = 'heroicon-o-shield-check'; | ||
|
||
protected static ?string $navigationGroup = 'Administration'; | ||
|
||
protected static ?int $navigationSort = 1; | ||
|
||
public static function form(Form $form): Form | ||
{ | ||
return $form | ||
->schema([ | ||
Forms\Components\TextInput::make('name') | ||
->required() | ||
->maxLength(125), | ||
Forms\Components\TextInput::make('guard_name') | ||
->required() | ||
->maxLength(125), | ||
]); | ||
} | ||
|
||
public static function table(Table $table): Table | ||
{ | ||
return $table | ||
->columns([ | ||
Tables\Columns\TextColumn::make('name') | ||
->searchable(), | ||
Tables\Columns\TextColumn::make('guard_name') | ||
->searchable(), | ||
Tables\Columns\TextColumn::make('created_at') | ||
->dateTime() | ||
->sortable() | ||
->toggleable(isToggledHiddenByDefault: true), | ||
Tables\Columns\TextColumn::make('updated_at') | ||
->dateTime() | ||
->sortable() | ||
->toggleable(isToggledHiddenByDefault: true), | ||
]) | ||
->actions([ | ||
Tables\Actions\ViewAction::make(), | ||
]) | ||
->bulkActions([ | ||
]); | ||
} | ||
|
||
public static function getRelations(): array | ||
{ | ||
return [ | ||
PermissionsRelationManager::class, | ||
]; | ||
} | ||
|
||
public static function getPages(): array | ||
{ | ||
return [ | ||
'index' => Pages\ListRoles::route('/'), | ||
'create' => Pages\CreateRole::route('/create'), | ||
'view' => Pages\ViewRole::route('/{record}'), | ||
'edit' => Pages\EditRole::route('/{record}/edit'), | ||
]; | ||
} | ||
|
||
public static function getEloquentQuery(): Builder | ||
{ | ||
return parent::getEloquentQuery() | ||
->withoutGlobalScopes([]); | ||
} | ||
} |
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,11 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\RoleResource\Pages; | ||
|
||
use App\Filament\Resources\RoleResource; | ||
use Filament\Resources\Pages\CreateRecord; | ||
|
||
class CreateRole extends CreateRecord | ||
{ | ||
protected static string $resource = RoleResource::class; | ||
} |
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,19 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\RoleResource\Pages; | ||
|
||
use Filament\Actions; | ||
use App\Filament\Resources\RoleResource; | ||
use Filament\Resources\Pages\EditRecord; | ||
|
||
class EditRole extends EditRecord | ||
{ | ||
protected static string $resource = RoleResource::class; | ||
|
||
protected function getHeaderActions(): array | ||
{ | ||
return [ | ||
Actions\ViewAction::make(), | ||
]; | ||
} | ||
} |
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,31 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\RoleResource\Pages; | ||
|
||
use Filament\Actions; | ||
use App\Filament\Resources\RoleResource; | ||
use Filament\Resources\Pages\ListRecords; | ||
use Filament\Resources\Pages\ListRecords\Tab; | ||
use Illuminate\Contracts\Database\Eloquent\Builder; | ||
|
||
class ListRoles extends ListRecords | ||
{ | ||
protected static string $resource = RoleResource::class; | ||
|
||
public function getTabs(): array | ||
{ | ||
return [ | ||
'web' => Tab::make('Web') | ||
->modifyQueryUsing(fn (Builder $query) => $query->web()), | ||
'api' => Tab::make('Api') | ||
->modifyQueryUsing(fn (Builder $query) => $query->api()), | ||
]; | ||
} | ||
|
||
protected function getHeaderActions(): array | ||
{ | ||
return [ | ||
Actions\CreateAction::make(), | ||
]; | ||
} | ||
} |
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,17 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\RoleResource\Pages; | ||
|
||
use App\Filament\Resources\RoleResource; | ||
use Filament\Resources\Pages\ViewRecord; | ||
|
||
class ViewRole extends ViewRecord | ||
{ | ||
protected static string $resource = RoleResource::class; | ||
|
||
protected function getHeaderActions(): array | ||
{ | ||
return [ | ||
]; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
app/Filament/Resources/RoleResource/RelationManagers/PermissionsRelationManager.php
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,48 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\RoleResource\RelationManagers; | ||
|
||
use Filament\Forms; | ||
use Filament\Tables; | ||
use Filament\Forms\Form; | ||
use Filament\Tables\Table; | ||
use Filament\Resources\RelationManagers\RelationManager; | ||
|
||
class PermissionsRelationManager extends RelationManager | ||
{ | ||
protected static string $relationship = 'permissions'; | ||
|
||
protected static ?string $recordTitleAttribute = 'name'; | ||
|
||
public function form(Form $form): Form | ||
{ | ||
return $form | ||
->schema([ | ||
Forms\Components\TextInput::make('name') | ||
->required() | ||
->maxLength(255), | ||
]); | ||
} | ||
|
||
public function table(Table $table): Table | ||
{ | ||
return $table | ||
->columns([ | ||
Tables\Columns\TextColumn::make('name'), | ||
]) | ||
->filters([ | ||
]) | ||
->headerActions([ | ||
Tables\Actions\CreateAction::make(), | ||
]) | ||
->actions([ | ||
Tables\Actions\EditAction::make(), | ||
Tables\Actions\DeleteAction::make(), | ||
]) | ||
->bulkActions([ | ||
Tables\Actions\BulkActionGroup::make([ | ||
Tables\Actions\DeleteBulkAction::make(), | ||
]), | ||
]); | ||
} | ||
} |
Oops, something went wrong.