public function amLoggedAs($user, $driver = null)
    {
        if (!$user instanceof Authenticatable) {
            $this->fail(
                'The user passed to amLoggedAs() should be an instance of \\Illuminate\\Contracts\\Auth\\Authenticatable'
            );
        }

        $guard = $auth = $this->app['auth'];

        if (method_exists($auth, 'driver')) {
            $guard = $auth->driver($driver);
        }

        if (method_exists($auth, 'guard')) {
            $guard = $auth->guard($driver);
        }

        $guard->setUser($user);
    }
public function amLoggedAs($user, $driver = null)
    {
        if (!$user instanceof Authenticatable) {
            $this->fail(
                'The user passed to amLoggedAs() should be an instance of \\Illuminate\\Contracts\\Auth\\Authenticatable'
            );
        }

        $guard = $auth = $this->app['auth'];

        if (method_exists($auth, 'driver')) {
            $guard = $auth->driver($driver);
        }

        if (method_exists($auth, 'guard')) {
            $guard = $auth->guard($driver);
        }

        $guard->setUser($user);
    }
public function amLoggedAs ( $ user , $ driver = null ) { if ( ! $ user instanceof Authenticatable ) { $ this -> fail ( 'The user passed to amLoggedAs() should be an instance of \\Illuminate\\Contracts\\Auth\\Authenticatable' ) ; } $ guard = $ auth = $ this -> app [ 'auth' ] ; if ( method_exists ( $ auth , 'driver' ) ) { $ guard = $ auth -> driver ( $ driver ) ; } if ( method_exists ( $ auth , 'guard' ) ) { $ guard = $ auth -> guard ( $ driver ) ; } $ guard -> setUser ( $ user ) ; }
Set the authenticated user for the next request.
This will not persist between multiple requests.

@param  \Illuminate\Contracts\Auth\Authenticatable
@param  string|null $driver The authentication driver for Lumen <= 5.1.*, guard name for Lumen >= 5.2
@return void
Set the authenticated user for the next request . This will not persist between multiple requests .