Closed Ceepster14 closed 7 months ago
Hi @Ceepster14 , sorry for the late reply.
Can you provide a minimum repository for reproduction?
Hi,
Apologies for the delay in replying.
I don't know whether there are some documentation issues here.
I decided to abandon using my own UI and use yours instead, which I kind of got working, however I did come across a few issues which might possibly point to a disconnect between the current package and the current documentation. If I follow your example for implementing the setImpersonateAuthorization method in my User model using a Boolean I have set on my user table to govern who can impersonate and who can be impersonated as follows:
public function setImpersonateAuthorization(Authorization $authorization) : void
{
$authorization->impersonator(function (User $user) {
return $user->is_super_user;
});
$authorization->impersonated(function (User $user) {
return !$user->is_super_user;
});
}
This throws the following error when it tries to evaluate the impersonated function:
App\Models\User::App\Models\{closure}(): Argument #1 ($user) must be of type App\Models\User, Octopy\Impersonate\Http\Resources\ImpersonateResource given
And the popup doesn't function and displays 'The results could not be loaded'
If I comment out the impersonated clause, but leave the impersonator clause, the pop-up works correctly and I can impersonate other users.
I also noticed in your example documentation covering this functionality that it references the Impersonate Concern:
use Octopy\Impersonate\Concerns\Impersonate;
But this concern does not exist in the package.
Hence my feeling that there's something out of sync between the docs and the package?
hi @Ceepster14 sorry, there was an typo in the documentation, it should have been Octopy\Impersonate\Concerns\HasImpersonation;
Can you try again?
Hi,
Yes, I'm using that concern, but this still exhibits the error detailed previously with 'impersonated' call.
@Ceepster14 okay, I have found the problem, while you can use this code to solve the problem while I fixed it.
$authorization->impersonated(function ($user){
return !$user->is_admin;
});
Thanks, I really appreciate your time on this! That works for me.
Thanks, I really appreciate your time on this! That works for me.
If you want to use the User
argument You can upgrade it to version 4.0.3, it has been fixed.
thank you for the report @Ceepster14
I'm trying to implement this package in a project using Laravel 11 (11.2.0) and Jetstream (5.0.2). I'm not using the UI as I'm initiating the impersonation through an existing CRUD. When trying to impersonate a user as follows:
$current_user->impersonate($impersonated_user);
Where $current_user is the currently logged in super user and $impersonated_user is the impersonation target, I get a Method Illuminate\Auth\RequestGuard::login does not exist exception thrown.
I believe I've followed the installation and configuration instructions correctly, but possibly I'm missing something?
Do you have any suggestions?