Laravel-mongodb: [Laravel 5.4] User model doesn't work

Created on 20 Apr 2017  路  11Comments  路  Source: jenssegers/laravel-mongodb

App/User.php

namespace App;

use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Eloquent implements Authenticatable
{
    use Notifiable;

    protected $collection = 'users';
}

config/app.php

Jenssegers\Mongodb\MongodbServiceProvider::class,

Error:

FatalErrorException in User.php line 9:
App\User cannot implement Illuminate\Foundation\Auth\User - it is not an interface
bug docs

Most helpful comment

Replace

use Illuminate\Foundation\Auth\User as Authenticatable;

with

use Jenssegers\Mongodb\Auth\User as Authenticatable;

It should look like this then

namespace App;

use Illuminate\Notifications\Notifiable;
use Jenssegers\Mongodb\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;

    protected $collection = 'users';
}

I do not think you can implement a class, only interfaces.

If this worked, please close this issue.

All 11 comments

Hi drewlag,

Try the following :

use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;

class User extends Eloquent implements AuthenticatableContract,

Replace

use Illuminate\Foundation\Auth\User as Authenticatable;

with

use Jenssegers\Mongodb\Auth\User as Authenticatable;

It should look like this then

namespace App;

use Illuminate\Notifications\Notifiable;
use Jenssegers\Mongodb\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;

    protected $collection = 'users';
}

I do not think you can implement a class, only interfaces.

If this worked, please close this issue.

use Jenssegers\Mongodb\Auth\User as Authenticatable;
This worked for me. Thank you @microwavekonijn

I would suggest adding this to the documentation in README.md.

Thank you @microwavekonijn.
This worked for me (using Laravel 5.5).
I lost way too much time finding this. How could it not be in the docs?!

This thread also helped me immensely. Cheers @microwavekonijn

This is not working on laravel 6.2

This is not working on laravel 6.2

Not working for me as well on Laravel 6

Same issue with Laravel 8

@nifunifatralara are you find any solution for laravel8? I also got trouble :(

@nifunifatralara are you find any solution for laravel8? I also got trouble :(

The answer has been given here multiple times.

Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

geofflancaster picture geofflancaster  路  3Comments

sanjay1688 picture sanjay1688  路  3Comments

yupangestu picture yupangestu  路  3Comments

kschethan picture kschethan  路  3Comments

viacheslavpleshkov picture viacheslavpleshkov  路  3Comments