ImpersonateController ​
File: src/Http/Controllers/ImpersonateController.php
Namespace: Unusualify\Modularous\Http\Controllers
Extends: Controller
Allows administrators to impersonate other users for debugging and support. The original admin session is preserved in the session so impersonation can be stopped at any time.
Constructor ​
php
public function __construct(AuthManager $auth)Methods ​
impersonate(int $id, UserRepository $users): RedirectResponse ​
Starts impersonating the user with the given $id.
- Checks that the authenticated user has the
impersonatepermission (viacan:impersonategate). - Stores the original admin's ID in
session('modularous.impersonate.original_id'). - Logs in as the target user via the modularous guard.
- Redirects to the dashboard.
stopImpersonate(): RedirectResponse ​
Ends the impersonation session.
- Reads the original admin ID from the session.
- Restores the admin user via the modularous guard.
- Removes the impersonation key from the session.
- Redirects to the dashboard.
Permission ​
The impersonate action is guarded by can:impersonate. Make sure this permission is assigned only to super-admin roles.
Related ​
- ImpersonateMiddleware — middleware that injects the impersonation banner