78 lines
2.0 KiB
PHP
78 lines
2.0 KiB
PHP
<?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 Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
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 = 'app.resource_roles';
|
|
|
|
protected static ?int $navigationSort = 6;
|
|
|
|
protected static ?string $recordTitleAttribute = 'name';
|
|
|
|
public static function getPluralLabel(): ?string
|
|
{
|
|
return __('app.resource_roles');
|
|
}
|
|
|
|
public static function getNavigationGroup(): ?string
|
|
{
|
|
return __('app.nav_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'),
|
|
];
|
|
}
|
|
|
|
// GlobalSearch customization
|
|
public static function modifyGlobalSearchQuery(Builder $query, string $search): void
|
|
{
|
|
$query->where('name', 'like', "%{$search}%");
|
|
}
|
|
|
|
public static function getGlobalSearchResultDetails(Model $record): array
|
|
{
|
|
return [
|
|
__('app.permissions') => $record->permissions->count() . ' quyền',
|
|
];
|
|
}
|
|
}
|