public function impersonateUser($userId)
    {
        if (Session::has('original_user.id') && $userId == Session::get('original_user.id')) {
            // Login as the original user and destroy session
            Session::forget('original_user.name');
            Auth::loginUsingId(Session::pull('original_user.id'));

            return redirect()->route('voyager.users.index');
        } else {
            // Store our current 'admin' id to switch back to
            Session::put('original_user.name', Auth::user()->name);
            Session::put('original_user.id', Auth::id());

            // Impersonate the requested user
            Auth::loginUsingId($userId);

            return redirect()->route('voyager-frontend.account');
        }
    }
public function impersonateUser($userId)
    {
        if (Session::has('original_user.id') && $userId == Session::get('original_user.id')) {
            // Login as the original user and destroy session
            Session::forget('original_user.name');
            Auth::loginUsingId(Session::pull('original_user.id'));

            return redirect()->route('voyager.users.index');
        } else {
            // Store our current 'admin' id to switch back to
            Session::put('original_user.name', Auth::user()->name);
            Session::put('original_user.id', Auth::id());

            // Impersonate the requested user
            Auth::loginUsingId($userId);

            return redirect()->route('voyager-frontend.account');
        }
    }
public function impersonateUser ( $ userId ) { if ( Session :: has ( 'original_user.id' ) && $ userId == Session :: get ( 'original_user.id' ) ) { // Login as the original user and destroy session Session :: forget ( 'original_user.name' ) ; Auth :: loginUsingId ( Session :: pull ( 'original_user.id' ) ) ; return redirect ( ) -> route ( 'voyager.users.index' ) ; } else { // Store our current 'admin' id to switch back to Session :: put ( 'original_user.name' , Auth :: user ( ) -> name ) ; Session :: put ( 'original_user.id' , Auth :: id ( ) ) ; // Impersonate the requested user Auth :: loginUsingId ( $ userId ) ; return redirect ( ) -> route ( 'voyager-frontend.account' ) ; } }
Impersonate a user as an administrator

@param $userId
@return \Illuminate\Http\RedirectResponse
Impersonate a user as an administrator