Laravel - Authentication - Adding Custom User Providers

If you are not using a traditional relational database to store your users, you will need to extend Laravel with your own authentication user provider. We will use the provider method on the Auth facade to define a custom user provider. The user provider resolver should return an implementation of Illuminate\Contracts\Auth\UserProvider:

            Auth::provider('mongo', function ($app, array $config) {
                // Return an instance of Illuminate\Contracts\Auth\UserProvider...
                return new MongoUserProvider($app->make('mongo.connection'));

After you have registered the provider using the provider method, you may switch to the new user provider in your auth.php configuration file. First, define a provider that uses your new driver:

    'providers' => [
        'users' => [
            'driver' => 'mongo',

Finally, you may reference this provider in your guards configuration:

    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',