Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble on impersonate from resources other than UserResource #74

Open
z4yed opened this issue Mar 6, 2024 · 4 comments
Open

Trouble on impersonate from resources other than UserResource #74

z4yed opened this issue Mar 6, 2024 · 4 comments

Comments

@z4yed
Copy link

z4yed commented Mar 6, 2024

I have a resource named InstructorResource. The Instructor model has a relational user method which belongs to User model.

I am trying to impersonate from InstructorResource by:

return $table
       ->actions([
                Impersonate::make()
                    ->redirectTo('/instructor'),

                Tables\Actions\ViewAction::make(),
                Tables\Actions\EditAction::make(),
            ]),

From the UserResource class, it is working perfectly though. Is it possible to impersonate from InstructResource?

@jszobody
Copy link
Member

If you look at the table action...

https://github.com/stechstudio/filament-impersonate/blob/master/src/Tables/Actions/Impersonate.php#L20C13-L20C66

... you can see how the current $record is being passed to the impersonate method. In theory, if the current $record is an instructor, you could probably do this:

Impersonate::make()
    ->redirectTo('/instructor')
    ->action(fn ($record) => $this->impersonate($record->user))

This is untested, but it seems like this sort of approach should work. I think you just need to manually handle the action, and tell the impersonate method where the actual user model is.

@z4yed
Copy link
Author

z4yed commented Mar 18, 2024

->actions([
  Impersonate::make()
      ->redirectTo('/instructor')
      ->action(fn($record) => $this->impersonate($record->user)),
  Tables\Actions\ViewAction::make(),
  Tables\Actions\EditAction::make(),
])

This code return the below error.

image

@jszobody jszobody reopened this Mar 18, 2024
@KonstantinosVazaios
Copy link

I am having the same issue. Tried to override the record method but did not work as well

@AurelDemiri
Copy link

@z4yed This should work:

            ->actions([
                Impersonate::make()
                    ->action(fn(Interpreter $record, Impersonate $action) => $action->impersonate($record->user)),
                Tables\Actions\EditAction::make(),
            ])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants