diff --git a/src/Services/ImpersonateManager.php b/src/Services/ImpersonateManager.php index 5bdd05a..026c8b5 100644 --- a/src/Services/ImpersonateManager.php +++ b/src/Services/ImpersonateManager.php @@ -193,10 +193,17 @@ public function getTakeRedirectTo(): string public function getLeaveRedirectTo(): string { + $routeName = config('laravel-impersonate.leave_redirect_to'); + + if (session()->has('laravel-impersonate:leave_redirect_to')) { + $routeName = session('laravel-impersonate:leave_redirect_to'); + session()->forget('laravel-impersonate:leave_redirect_to'); + } + try { - $uri = route(config('laravel-impersonate.leave_redirect_to')); + $uri = route($routeName); } catch (\InvalidArgumentException $e) { - $uri = config('laravel-impersonate.leave_redirect_to'); + $uri = $routeName; } return $uri;