F
Filament2y ago
Gush

UsersRelationManager

i have a groups resource with a UsersRelationManager where is_owner can acess but in the table i dont want to appear in the table so i dont acidently delete myself from that group... I tried something like this:
public static function getEloquentQuery(): Builder
{
$authenticatedUserId = auth()->user()->id;

return User::query()->whereNotIn('id', [$authenticatedUserId]);
}
public static function getEloquentQuery(): Builder
{
$authenticatedUserId = auth()->user()->id;

return User::query()->whereNotIn('id', [$authenticatedUserId]);
}
but i still appear in the table
3 Replies
Dennis Koch
Dennis Koch2y ago
Looks good. Is this on the UserResource? If it's only about deleting, you could also disable delete action for you user:
DeleteAction::make()
->hidden(fn ($record) => $record->id === auth()->id())
DeleteAction::make()
->hidden(fn ($record) => $record->id === auth()->id())
Gush
GushOP2y ago
no, its in the GroupResource with a getRelations
public static function getRelations(): array
{
return [
UsersRelationManager::class,
];
}
public static function getRelations(): array
{
return [
UsersRelationManager::class,
];
}
in my FilamentServiceProvider i made it so only a is_owner can access this RelationManager being redirected to the edit of his group, so it would make sense the user can delete other users, just not himself this approach worked but still im not satisfied that myself has a owner appear in the table
Dennis Koch
Dennis Koch2y ago
Sorry, when I looked at the code, I forgot about the relation manager again. Overwire getTableQuery() on the relation manager instead of getEloquentQuery()
Want results from more Discord servers?
Add your server