Initial commit
This commit is contained in:
11
app/Filament/Resources/Roles/Pages/CreateRole.php
Normal file
11
app/Filament/Resources/Roles/Pages/CreateRole.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Roles\Pages;
|
||||
|
||||
use App\Filament\Resources\Roles\RoleResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateRole extends CreateRecord
|
||||
{
|
||||
protected static string $resource = RoleResource::class;
|
||||
}
|
||||
19
app/Filament/Resources/Roles/Pages/EditRole.php
Normal file
19
app/Filament/Resources/Roles/Pages/EditRole.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Roles\Pages;
|
||||
|
||||
use App\Filament\Resources\Roles\RoleResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditRole extends EditRecord
|
||||
{
|
||||
protected static string $resource = RoleResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
19
app/Filament/Resources/Roles/Pages/ListRoles.php
Normal file
19
app/Filament/Resources/Roles/Pages/ListRoles.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Roles\Pages;
|
||||
|
||||
use App\Filament\Resources\Roles\RoleResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListRoles extends ListRecords
|
||||
{
|
||||
protected static string $resource = RoleResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
72
app/Filament/Resources/Roles/RoleResource.php
Normal file
72
app/Filament/Resources/Roles/RoleResource.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Roles;
|
||||
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use App\Filament\Resources\Roles\Pages\CreateRole;
|
||||
use App\Filament\Resources\Roles\Pages\EditRole;
|
||||
use App\Filament\Resources\Roles\Pages\ListRoles;
|
||||
use App\Filament\Resources\Roles\Pages\ViewRole;
|
||||
use App\Filament\Resources\Roles\Schemas\RoleForm;
|
||||
use App\Filament\Resources\Roles\Schemas\RoleInfolist;
|
||||
use App\Filament\Resources\Roles\Tables\RolesTable;
|
||||
use Spatie\Permission\Models\Role;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class RoleResource extends Resource
|
||||
{
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return auth()->user()?->can('admin') ?? false;
|
||||
}
|
||||
|
||||
protected static ?string $model = Role::class;
|
||||
|
||||
protected static string | \BackedEnum | null $navigationIcon = 'heroicon-o-user-group';
|
||||
protected static string | \UnitEnum | null $navigationGroup = 'Ustawienia';
|
||||
protected static ?string $pluralModelLabel = 'Role';
|
||||
protected static ?string $modelLabel = 'Role';
|
||||
protected static ?int $navigationSort = 3;
|
||||
protected static ?string $recordTitleAttribute = 'Role';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return RoleForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function infolist(Schema $schema): Schema
|
||||
{
|
||||
return RoleInfolist::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return RolesTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListRoles::route('/'),
|
||||
'create' => CreateRole::route('/create'),
|
||||
'edit' => EditRole::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function shouldRegister(): bool
|
||||
{
|
||||
return auth()->user()?->can('edit_users') ?? false;
|
||||
}
|
||||
}
|
||||
26
app/Filament/Resources/Roles/Schemas/RoleForm.php
Normal file
26
app/Filament/Resources/Roles/Schemas/RoleForm.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Roles\Schemas;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class RoleForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
TextInput::make('name')
|
||||
->label('Nazwa')
|
||||
->required()
|
||||
->unique(ignoreRecord: true),
|
||||
Select::make('permissions')
|
||||
->label('Uprawnienia')
|
||||
->multiple()
|
||||
->relationship('permissions', 'name')
|
||||
->preload()
|
||||
->searchable(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
16
app/Filament/Resources/Roles/Schemas/RoleInfolist.php
Normal file
16
app/Filament/Resources/Roles/Schemas/RoleInfolist.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Roles\Schemas;
|
||||
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class RoleInfolist
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
//
|
||||
]);
|
||||
}
|
||||
}
|
||||
41
app/Filament/Resources/Roles/Tables/RolesTable.php
Normal file
41
app/Filament/Resources/Roles/Tables/RolesTable.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Roles\Tables;
|
||||
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
|
||||
class RolesTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('name')
|
||||
->label('Nazwa')
|
||||
->searchable(),
|
||||
TextColumn::make('permissions_count')
|
||||
->counts('permissions')
|
||||
->label('Uprawnienia'),
|
||||
TextColumn::make('created_at')
|
||||
->label('Data utworzenia')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user