Skip to content

Instantly share code, notes, and snippets.

@shankar-bavan
Created September 14, 2019 06:04
Show Gist options
  • Save shankar-bavan/ebe92478a4492c5b71458fed94afbd4e to your computer and use it in GitHub Desktop.
Save shankar-bavan/ebe92478a4492c5b71458fed94afbd4e to your computer and use it in GitHub Desktop.
Mongo DB laravel authentication with jenssegers-mongodb

Install using composer:

composer require jenssegers/mongodb-session

config/app.php

'providers' => [
Jenssegers\Mongodb\MongodbServiceProvider::class,
Jenssegers\Mongodb\Session\SessionServiceProvider::class, 
Jenssegers\Mongodb\Auth\PasswordResetServiceProvider::class,

Change the session driver in app/config/session.php to mongodb

'driver' => 'mongodb',

Optional: change the connection to a connection using the mongodb driver from app/config/database.php:

'connection' => 'mongodb',

User model

namespace App;

use Illuminate\Notifications\Notifiable;
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
use Illuminate\Auth\Authenticatable;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;

class User extends Eloquent implements AuthenticatableContract, AuthorizableContract, CanResetPasswordContract
{
    use Authenticatable, Authorizable, CanResetPassword;
    use Notifiable;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment