Reputation: 4114
I want to use MongoDB with Laravel 5.3. For that I have found this package:
https://github.com/jenssegers/laravel-mongodb
I have setup MongoDB on my machine and database connection with Laravel too.
I'm also able to run queries using Laravel Eloquent and Query builder.
The only issue is with authentication.
In order to use this package with Laravel, we need to extend its Eloquent class in each model like:
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class User extends Eloquent {}
But User model provided by Laravel 5.3 already extends Authenticatable class and PHP doesn't support multiple inheritance. So, what is the solution here?
https://github.com/laravel/laravel/blob/master/app/User.php
I would prefer a solution in which User model provided by Laravel 5.3 doesn't need to be modified much.
Thanks,
Parth vora
Upvotes: 2
Views: 2359
Reputation: 163978
I have 5.2 project and auth system works just fine with jenssegers/laravel-mongodb
. You should add Jenssegers\Mongodb\Auth\PasswordResetServiceProvider
if you're using password reminders.
If you don't use password reminders, you don't have to register this service provider and everything else should work just fine.
https://github.com/jenssegers/laravel-mongodb#extensions
Also, here's my working User.php
, maybe it will help:
namespace App;
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;
Upvotes: 2