F
Filamentโ€ข14mo ago
DS

is there a way to use spatie roles with teams id and filament multenancy on V3 ?

im trying to implement tenancy on v3 using filament multitenancy and also use spatie roles team functionality https://spatie.be/docs/laravel-permission/v5/basic-usage/teams-permissions at this point i can use roles and permissions and create the role with the tenant id associated butt i can'tmake it work in the relationship manager
<?php

namespace App\Filament\Panel\Resources\UserResource\RelationManagers;

use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Table;


class RoleRelationManager 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\AttachAction::make()
->preloadRecordSelect()
])
->actions([
Tables\Actions\DetachAction::make(),
])
->bulkActions([
Tables\Actions\DetachBulkAction::make(),
]);
}
}
<?php

namespace App\Filament\Panel\Resources\UserResource\RelationManagers;

use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Table;


class RoleRelationManager 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\AttachAction::make()
->preloadRecordSelect()
])
->actions([
Tables\Actions\DetachAction::make(),
])
->bulkActions([
Tables\Actions\DetachBulkAction::make(),
]);
}
}
any help will be appreciated ๐Ÿ™‚
73 Replies
DS
DSโ€ข14mo ago
@justjosef hello, here is the post!
josef
josefโ€ข14mo ago
What exactly is not working? You're not getting the tenant-specific roles? @ds_9206 ?
DS
DSโ€ข14mo ago
yes im not having the tenant specific roles when im trying to attach the roles to the model user even if the role has the teams_id with the team id asociated
BKF Dev
BKF Devโ€ข14mo ago
+1 Confirmed, same issue with me, the tenant_id isn't included automatically
josef
josefโ€ข14mo ago
You have to adapt the queries in the relation manager to only fetch, show, associate (and so on) the roles for the current client by scoping the used queries
BKF Dev
BKF Devโ€ข14mo ago
Hi, thanks for reply, the problem is not related to scope query, in my case, I can create roles on its CreatePanel, but if I create it using relation manager, an error says : General error: 1364 Field 'team_id' doesn't have a default value
josef
josefโ€ข14mo ago
yeah, because the field/parameter is not set. You have to set it to current team id on creation
BKF Dev
BKF Devโ€ข14mo ago
but we should not set it since we're already in the right tenant Id, you may check my repository and test it : https://github.com/aeq-dev/filamentv3-bug-7511
GitHub
GitHub - aeq-dev/filamentv3-bug-7511
Contribute to aeq-dev/filamentv3-bug-7511 development by creating an account on GitHub.
josef
josefโ€ข14mo ago
Yes, you are 'in' the right tenant, but how would the relation manager know to set an arbitrary parameter on the model (team_id on role) to the current tenant id?
BKF Dev
BKF Devโ€ข14mo ago
by the same method where we can create role without using relation manager and without setting the team id
josef
josefโ€ข14mo ago
How do you do that? In your linked repository, I don't see a RoleResource
BKF Dev
BKF Devโ€ข14mo ago
In my case it's the package user belongstomany package
josef
josefโ€ข14mo ago
I see, so it's a different question, not about the roles per se
Want results from more Discord servers?
Add your server