Skip to content

Commit

Permalink
FEATURE - Add Users relationship into Roles (#51)
Browse files Browse the repository at this point in the history
* Add role nagivation group customisation

* Add permission nagivation group customisation

* Add nagivation_section_group config option

* Remove default setting on Guard

Remove default setting on Guard because it causes an issue with the datalist being array if it's not selected / typed.

* Remove default setting on Guard

Remove default setting on Guard because it causes an issue with the datalist being array if it's not selected / typed.

* Add team support to RolesResource

* Add english language strings for team support

* Added Team Model Class linkage

* Add dehydrated state to the team_id to allow null when empty since 0 is an integer.

* Remove duplicated team_model from merging.

* Basic First Pass for adding users to roles, so you can see at the role level.
TODO - Condition for teams support if possible.

---------

Co-authored-by: Tony Partridge <[email protected]>
  • Loading branch information
tonypartridge and tonypartridger authored Jun 27, 2023
1 parent ca28592 commit 4734c9a
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
3 changes: 2 additions & 1 deletion resources/lang/en/filament-spatie.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
'section.roles' => 'Roles',
'section.roles_and_permissions' => 'Roles and Permissions',
'select-team' => 'Select a Team',
'select-team-hint' => 'Leave blank for a global role'
'select-team-hint' => 'Leave blank for a global role',
'section.users' => 'Users'
];
2 changes: 2 additions & 0 deletions src/Resources/RoleResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Althinect\FilamentSpatieRolesPermissions\Resources\RoleResource\Pages\ListRoles;
use Althinect\FilamentSpatieRolesPermissions\Resources\RoleResource\Pages\ViewRole;
use Althinect\FilamentSpatieRolesPermissions\Resources\RoleResource\RelationManager\PermissionRelationManager;
use Althinect\FilamentSpatieRolesPermissions\Resources\RoleResource\RelationManager\UserRelationManager;
use Filament\Forms\Components\Card;
use Filament\Forms\Components\Grid;
use Filament\Forms\Components\MultiSelect;
Expand Down Expand Up @@ -103,6 +104,7 @@ public static function getRelations(): array
{
return [
PermissionRelationManager::class,
UserRelationManager::class,
];
}

Expand Down
50 changes: 50 additions & 0 deletions src/Resources/RoleResource/RelationManager/UserRelationManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Althinect\FilamentSpatieRolesPermissions\Resources\RoleResource\RelationManager;

use Filament\Forms;
use Filament\Forms\Components\TextInput;
use Filament\Resources\Form;
use Filament\Resources\RelationManagers\BelongsToManyRelationManager;
use Filament\Resources\Table;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;

class UserRelationManager extends BelongsToManyRelationManager
{
protected static string $relationship = 'users';

protected static ?string $recordTitleAttribute = 'name';

protected static function getModelLabel(): string
{
return __('filament-spatie-roles-permissions::filament-spatie.section.users');
}

protected static function getPluralModelLabel(): string
{
return __('filament-spatie-roles-permissions::filament-spatie.section.users');
}

public static function form(Form $form): Form
{
return $form
->schema([
TextInput::make('name')
->label(__('filament-spatie-roles-permissions::filament-spatie.field.name')),
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('name')
->searchable()
->label(__('filament-spatie-roles-permissions::filament-spatie.field.name')),
])
->filters([
//
]);
}
}

0 comments on commit 4734c9a

Please sign in to comment.