feat: granular permissions, export backup, user/role management
- PermissionSeeder: 29 permissions with role mapping (admin/manager/staff) - Policies updated to use hasPermissionTo() instead of hasRole() - ExportBackup command: JSON per-table backup with chunk processing - UserResource: CRUD users with role assignment (admin only) - RoleResource: CRUD roles with permission assignment (admin only) - UserPolicy + RolePolicy: admin-only access control - ImportCskh: detailed skip logging with color in dry-run mode - Widgets: permission-based visibility checks - Tests: 8/8 pass (21 assertions)
This commit is contained in:
@@ -36,7 +36,7 @@ class EditFeedback extends EditRecord
|
||||
->label('Transfer Department')
|
||||
->icon('heroicon-o-arrows-right-left')
|
||||
->color('warning')
|
||||
->visible(fn (): bool => auth()->user()->hasRole(['admin', 'manager']))
|
||||
->visible(fn (): bool => auth()->user()->hasPermissionTo('transfer-department'))
|
||||
->form([
|
||||
Select::make('to_department_id')
|
||||
->label('Target Department')
|
||||
@@ -106,7 +106,7 @@ class EditFeedback extends EditRecord
|
||||
->label('Close Ticket')
|
||||
->icon('heroicon-o-check-circle')
|
||||
->color('success')
|
||||
->visible(fn (): bool => $this->getRecord()->status !== 'closed' && auth()->user()->hasRole(['admin', 'manager']))
|
||||
->visible(fn (): bool => $this->getRecord()->status !== 'closed' && auth()->user()->hasPermissionTo('close-ticket'))
|
||||
->requiresConfirmation()
|
||||
->modalHeading('Close Ticket')
|
||||
->modalDescription('Bạn có chắc muốn đóng phiếu này? Hành động này KHÔNG thể hoàn tác.')
|
||||
|
||||
@@ -53,7 +53,7 @@ class InteractionsRelationManager extends RelationManager
|
||||
|
||||
Select::make('new_status')
|
||||
->label('New Status')
|
||||
->options(fn (): array => auth()->user()->hasRole(['admin', 'manager'])
|
||||
->options(fn (): array => auth()->user()->hasPermissionTo('close-ticket')
|
||||
? ['pending' => 'Pending', 'processing' => 'Processing', 'resolved' => 'Resolved', 'closed' => 'Closed']
|
||||
: ['pending' => 'Pending', 'processing' => 'Processing', 'resolved' => 'Resolved'],
|
||||
)
|
||||
|
||||
@@ -11,6 +11,7 @@ use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Components\Grid;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class FeedbackForm
|
||||
@@ -19,18 +20,22 @@ class FeedbackForm
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Section::make('Feedback Information')
|
||||
Section::make('Customer & Product')
|
||||
->description('Select the customer and their associated product')
|
||||
->icon('heroicon-o-user-group')
|
||||
->schema([
|
||||
Select::make('customer_id')
|
||||
->relationship('customer', 'name')
|
||||
->searchable()
|
||||
->required()
|
||||
->live(),
|
||||
->live()
|
||||
->columnSpan(1),
|
||||
|
||||
Toggle::make('is_general')
|
||||
->label('General feedback (not related to a product)')
|
||||
->default(false)
|
||||
->live(),
|
||||
->live()
|
||||
->columnSpan(1),
|
||||
|
||||
Select::make('customer_product_id')
|
||||
->label('Product')
|
||||
@@ -57,7 +62,7 @@ class FeedbackForm
|
||||
->live(),
|
||||
|
||||
Select::make('contract_id')
|
||||
->label('Hợp đồng')
|
||||
->label('Contract')
|
||||
->visible(fn ($get): bool => ! $get('is_general') && filled($get('customer_product_id')))
|
||||
->options(function ($get): array {
|
||||
$customerProductId = $get('customer_product_id');
|
||||
@@ -102,48 +107,46 @@ class FeedbackForm
|
||||
})
|
||||
->nullable()
|
||||
->searchable(),
|
||||
])
|
||||
->columns(2),
|
||||
|
||||
Section::make('Feedback Details')
|
||||
->description('Describe the customer feedback')
|
||||
->icon('heroicon-o-chat-bubble-left-right')
|
||||
->schema([
|
||||
Select::make('feedback_channel_id')
|
||||
->relationship('feedbackChannel', 'name')
|
||||
->required()
|
||||
->preload(),
|
||||
->preload()
|
||||
->columnSpan(1),
|
||||
|
||||
TextInput::make('title')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
->maxLength(255)
|
||||
->columnSpan(1),
|
||||
|
||||
Textarea::make('content')
|
||||
->required()
|
||||
->rows(6)
|
||||
->columnSpanFull(),
|
||||
|
||||
Select::make('attachment_collection')
|
||||
->label('Attachment Collection')
|
||||
->options([
|
||||
'general' => 'General',
|
||||
'proof_of_resolution' => 'Proof of Resolution',
|
||||
'customer_evidence' => 'Customer Evidence',
|
||||
])
|
||||
->default('general'),
|
||||
|
||||
FileUpload::make('attachments')
|
||||
->label('Attachments')
|
||||
->multiple()
|
||||
->disk('local')
|
||||
->directory('feedback-attachments')
|
||||
->columnSpanFull()
|
||||
->dehydrated(false),
|
||||
|
||||
Select::make('tags')
|
||||
->relationship('tags', 'name')
|
||||
->multiple()
|
||||
->preload()
|
||||
->columnSpanFull()
|
||||
->createOptionForm([
|
||||
TextInput::make('name')->required(),
|
||||
TextInput::make('slug')->required(),
|
||||
ColorPicker::make('color')->default('#3b82f6'),
|
||||
]),
|
||||
])
|
||||
->columns(2),
|
||||
|
||||
Section::make('Assignment & Status')
|
||||
->description('Assign handler and set initial status')
|
||||
->icon('heroicon-o-arrow-path-rounded-square')
|
||||
->schema([
|
||||
Select::make('status')
|
||||
->options([
|
||||
'pending' => 'Pending',
|
||||
@@ -152,22 +155,50 @@ class FeedbackForm
|
||||
'closed' => 'Closed',
|
||||
])
|
||||
->default('pending')
|
||||
->required(),
|
||||
->required()
|
||||
->columnSpan(1),
|
||||
|
||||
Select::make('assigned_to')
|
||||
->relationship('assignedTo', 'name')
|
||||
->searchable()
|
||||
->nullable(),
|
||||
->nullable()
|
||||
->columnSpan(1),
|
||||
|
||||
Select::make('current_department_id')
|
||||
->label('Department')
|
||||
->options(Department::pluck('name', 'id')->toArray())
|
||||
->searchable()
|
||||
->nullable(),
|
||||
->nullable()
|
||||
->columnSpan(1),
|
||||
|
||||
Toggle::make('is_escalated')
|
||||
->label('Escalated')
|
||||
->visible(fn (): bool => auth()->user()?->hasRole(['admin', 'manager']) ?? false),
|
||||
->visible(fn (): bool => auth()->user()?->hasPermissionTo('close-ticket') ?? false)
|
||||
->columnSpan(1),
|
||||
])
|
||||
->columns(2),
|
||||
|
||||
Section::make('Attachments')
|
||||
->description('Upload files related to this feedback')
|
||||
->icon('heroicon-o-paper-clip')
|
||||
->schema([
|
||||
Select::make('attachment_collection')
|
||||
->label('Collection')
|
||||
->options([
|
||||
'general' => 'General',
|
||||
'proof_of_resolution' => 'Proof of Resolution',
|
||||
'customer_evidence' => 'Customer Evidence',
|
||||
])
|
||||
->default('general')
|
||||
->columnSpan(1),
|
||||
|
||||
FileUpload::make('attachments')
|
||||
->label('Files')
|
||||
->multiple()
|
||||
->disk('local')
|
||||
->directory('feedback-attachments')
|
||||
->columnSpan(1)
|
||||
->dehydrated(false),
|
||||
])
|
||||
->columns(2),
|
||||
]);
|
||||
|
||||
@@ -16,16 +16,28 @@ class FeedbackTable
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('id')
|
||||
->label('#')
|
||||
->sortable()
|
||||
->weight('bold')
|
||||
->color('primary'),
|
||||
|
||||
TextColumn::make('title')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
->sortable()
|
||||
->weight('semibold')
|
||||
->limit(40),
|
||||
|
||||
TextColumn::make('customer.name')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('customerProduct.product.name')
|
||||
->label('Product')
|
||||
->placeholder('General')
|
||||
->sortable(),
|
||||
->sortable()
|
||||
->toggleable(),
|
||||
|
||||
TextColumn::make('contract.type')
|
||||
->label('Contract')
|
||||
->badge()
|
||||
@@ -38,17 +50,17 @@ class FeedbackTable
|
||||
})
|
||||
->placeholder('-')
|
||||
->toggleable(),
|
||||
|
||||
TextColumn::make('feedbackChannel.name')
|
||||
->label('Channel')
|
||||
->formatStateUsing(fn ($state, $record) => sprintf(
|
||||
'<span style="display:inline-block;background:%s;color:#fff;padding:2px 10px;border-radius:9999px;font-size:0.75rem;">%s</span>',
|
||||
$record->feedbackChannel?->color ?: '#6b7280',
|
||||
e($state)
|
||||
))
|
||||
->html(),
|
||||
->badge()
|
||||
->color('gray'),
|
||||
|
||||
TextColumn::make('tags.name')
|
||||
->badge()
|
||||
->separator(','),
|
||||
->separator(',')
|
||||
->toggleable(),
|
||||
|
||||
TextColumn::make('status')
|
||||
->badge()
|
||||
->color(fn(string $state): string => match ($state) {
|
||||
@@ -58,20 +70,28 @@ class FeedbackTable
|
||||
'closed' => 'gray',
|
||||
default => 'gray',
|
||||
}),
|
||||
|
||||
TextColumn::make('currentDepartment.name')
|
||||
->label('Department')
|
||||
->badge()
|
||||
->color('info')
|
||||
->toggleable(),
|
||||
|
||||
TextColumn::make('assignedTo.name')
|
||||
->label('Assigned To')
|
||||
->toggleable(),
|
||||
|
||||
IconColumn::make('is_escalated')
|
||||
->label('Escalated')
|
||||
->boolean()
|
||||
->toggleable(),
|
||||
|
||||
TextColumn::make('created_at')
|
||||
->dateTime()
|
||||
->label('Created')
|
||||
->since()
|
||||
->sortable()
|
||||
->toggleable(),
|
||||
->toggleable()
|
||||
->color('secondary'),
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('status')
|
||||
|
||||
22
app/Filament/Resources/Roles/Pages/CreateRole.php
Normal file
22
app/Filament/Resources/Roles/Pages/CreateRole.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Roles\Pages;
|
||||
|
||||
use App\Filament\Resources\Roles\RoleResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
|
||||
class CreateRole extends CreateRecord
|
||||
{
|
||||
protected static string $resource = RoleResource::class;
|
||||
|
||||
protected function afterCreate(): void
|
||||
{
|
||||
$record = $this->record;
|
||||
$permissionNames = $this->data['permissions'] ?? [];
|
||||
|
||||
if (! empty($permissionNames)) {
|
||||
$record->syncPermissions($permissionNames);
|
||||
}
|
||||
}
|
||||
}
|
||||
35
app/Filament/Resources/Roles/Pages/EditRole.php
Normal file
35
app/Filament/Resources/Roles/Pages/EditRole.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Roles\Pages;
|
||||
|
||||
use App\Filament\Resources\Roles\RoleResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditRole extends EditRecord
|
||||
{
|
||||
protected static string $resource = RoleResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function afterSave(): void
|
||||
{
|
||||
$record = $this->record;
|
||||
$permissionNames = $this->data['permissions'] ?? [];
|
||||
|
||||
$record->syncPermissions($permissionNames);
|
||||
}
|
||||
|
||||
protected function mutateFormDataBeforeFill(array $data): array
|
||||
{
|
||||
$role = $this->record;
|
||||
$data['permissions'] = $role->permissions->pluck('name')->toArray();
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
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;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListRoles extends ListRecords
|
||||
{
|
||||
protected static string $resource = RoleResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
57
app/Filament/Resources/Roles/RoleResource.php
Normal file
57
app/Filament/Resources/Roles/RoleResource.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Roles;
|
||||
|
||||
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\Schemas\RoleForm;
|
||||
use App\Filament\Resources\Roles\Tables\RolesTable;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use Spatie\Permission\Models\Role;
|
||||
|
||||
class RoleResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Role::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedShieldCheck;
|
||||
|
||||
protected static ?string $pluralLabel = 'Roles';
|
||||
|
||||
protected static ?int $navigationSort = 6;
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
public static function getNavigationGroup(): ?string
|
||||
{
|
||||
return 'Management';
|
||||
}
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return RoleForm::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'),
|
||||
];
|
||||
}
|
||||
}
|
||||
37
app/Filament/Resources/Roles/Schemas/RoleForm.php
Normal file
37
app/Filament/Resources/Roles/Schemas/RoleForm.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Roles\Schemas;
|
||||
|
||||
use Filament\Forms\Components\CheckboxList;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
|
||||
class RoleForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Section::make()
|
||||
->schema([
|
||||
TextInput::make('name')
|
||||
->label('Role Name')
|
||||
->required()
|
||||
->maxLength(255)
|
||||
->unique(ignoreRecord: true),
|
||||
]),
|
||||
|
||||
Section::make('Permissions')
|
||||
->description('Chọn quyền cho role này')
|
||||
->schema([
|
||||
CheckboxList::make('permissions')
|
||||
->label('')
|
||||
->options(fn () => Permission::orderBy('name')->pluck('name', 'name')->toArray())
|
||||
->columns(4)
|
||||
->columnSpanFull(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
63
app/Filament/Resources/Roles/Tables/RolesTable.php
Normal file
63
app/Filament/Resources/Roles/Tables/RolesTable.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Roles\Tables;
|
||||
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class RolesTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('id')
|
||||
->label('#')
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('name')
|
||||
->label('Role Name')
|
||||
->searchable()
|
||||
->sortable()
|
||||
->badge()
|
||||
->color(fn (string $state): string => match ($state) {
|
||||
'admin' => 'danger',
|
||||
'manager' => 'warning',
|
||||
'staff' => 'info',
|
||||
default => 'gray',
|
||||
}),
|
||||
|
||||
TextColumn::make('permissions_count')
|
||||
->label('Permissions')
|
||||
->counts('permissions')
|
||||
->badge()
|
||||
->color('primary'),
|
||||
|
||||
TextColumn::make('users_count')
|
||||
->label('Users')
|
||||
->counts('users')
|
||||
->badge()
|
||||
->color('success'),
|
||||
|
||||
TextColumn::make('created_at')
|
||||
->dateTime('d/m/Y H:i')
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->defaultSort('id', 'asc')
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
20
app/Filament/Resources/Users/Pages/CreateUser.php
Normal file
20
app/Filament/Resources/Users/Pages/CreateUser.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Users\Pages;
|
||||
|
||||
use App\Filament\Resources\Users\UserResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateUser extends CreateRecord
|
||||
{
|
||||
protected static string $resource = UserResource::class;
|
||||
|
||||
protected function afterCreate(): void
|
||||
{
|
||||
$record = $this->record;
|
||||
$role = $record->role;
|
||||
|
||||
// Assign the primary role
|
||||
$record->syncRoles([$role]);
|
||||
}
|
||||
}
|
||||
27
app/Filament/Resources/Users/Pages/EditUser.php
Normal file
27
app/Filament/Resources/Users/Pages/EditUser.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Users\Pages;
|
||||
|
||||
use App\Filament\Resources\Users\UserResource;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditUser extends EditRecord
|
||||
{
|
||||
protected static string $resource = UserResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
\Filament\Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function afterSave(): void
|
||||
{
|
||||
$record = $this->record;
|
||||
$role = $record->role;
|
||||
|
||||
// Sync the primary role
|
||||
$record->syncRoles([$role]);
|
||||
}
|
||||
}
|
||||
37
app/Filament/Resources/Users/Pages/ListUsers.php
Normal file
37
app/Filament/Resources/Users/Pages/ListUsers.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Users\Pages;
|
||||
|
||||
use App\Filament\Resources\Users\UserResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Filament\Schemas\Components\Tabs\Tab;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class ListUsers extends ListRecords
|
||||
{
|
||||
protected static string $resource = UserResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
public function getTabs(): array
|
||||
{
|
||||
return [
|
||||
'all' => Tab::make(),
|
||||
'admin' => Tab::make()
|
||||
->modifyQueryUsing(fn (Builder $query) => $query->where('role', 'admin'))
|
||||
->badge(fn () => static::getResource()::getModel()::where('role', 'admin')->count()),
|
||||
'manager' => Tab::make()
|
||||
->modifyQueryUsing(fn (Builder $query) => $query->where('role', 'manager'))
|
||||
->badge(fn () => static::getResource()::getModel()::where('role', 'manager')->count()),
|
||||
'staff' => Tab::make()
|
||||
->modifyQueryUsing(fn (Builder $query) => $query->where('role', 'staff'))
|
||||
->badge(fn () => static::getResource()::getModel()::where('role', 'staff')->count()),
|
||||
];
|
||||
}
|
||||
}
|
||||
42
app/Filament/Resources/Users/Schemas/UserForm.php
Normal file
42
app/Filament/Resources/Users/Schemas/UserForm.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Users\Schemas;
|
||||
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Schema;
|
||||
use Spatie\Permission\Models\Role;
|
||||
|
||||
class UserForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
TextInput::make('name')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
|
||||
TextInput::make('email')
|
||||
->email()
|
||||
->required()
|
||||
->maxLength(255)
|
||||
->unique(ignoreRecord: true),
|
||||
|
||||
TextInput::make('password')
|
||||
->password()
|
||||
->revealable()
|
||||
->required(fn (string $operation): bool => $operation === 'create')
|
||||
->dehydrateStateUsing(fn (?string $state): ?string => filled($state) ? bcrypt($state) : null)
|
||||
->dehydrated(fn (?string $state): bool => filled($state))
|
||||
->maxLength(255)
|
||||
->columnSpanFull(),
|
||||
|
||||
Select::make('role')
|
||||
->label('Role')
|
||||
->options(Role::pluck('name', 'name')->toArray())
|
||||
->required()
|
||||
->searchable(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
59
app/Filament/Resources/Users/Tables/UsersTable.php
Normal file
59
app/Filament/Resources/Users/Tables/UsersTable.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Users\Tables;
|
||||
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class UsersTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('id')
|
||||
->label('#')
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('name')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('email')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('role')
|
||||
->badge()
|
||||
->color(fn (string $state): string => match ($state) {
|
||||
'admin' => 'danger',
|
||||
'manager' => 'warning',
|
||||
'staff' => 'info',
|
||||
default => 'gray',
|
||||
}),
|
||||
|
||||
TextColumn::make('created_at')
|
||||
->dateTime('d/m/Y H:i')
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->defaultSort('id', 'asc')
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
])
|
||||
->headerActions([
|
||||
//
|
||||
])
|
||||
->bulkActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
57
app/Filament/Resources/Users/UserResource.php
Normal file
57
app/Filament/Resources/Users/UserResource.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Users;
|
||||
|
||||
use App\Filament\Resources\Users\Pages\CreateUser;
|
||||
use App\Filament\Resources\Users\Pages\EditUser;
|
||||
use App\Filament\Resources\Users\Pages\ListUsers;
|
||||
use App\Filament\Resources\Users\Schemas\UserForm;
|
||||
use App\Filament\Resources\Users\Tables\UsersTable;
|
||||
use App\Models\User;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class UserResource extends Resource
|
||||
{
|
||||
protected static ?string $model = User::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedUsers;
|
||||
|
||||
protected static ?string $pluralLabel = 'Users';
|
||||
|
||||
protected static ?int $navigationSort = 5;
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
public static function getNavigationGroup(): ?string
|
||||
{
|
||||
return 'Management';
|
||||
}
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return UserForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return UsersTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListUsers::route('/'),
|
||||
'create' => CreateUser::route('/create'),
|
||||
'edit' => EditUser::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user