laravel-mongodb icon indicating copy to clipboard operation
laravel-mongodb copied to clipboard

[Laravel 5.4] User model doesn't work

Open alagaccia opened this issue 7 years ago • 11 comments

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

alagaccia avatar Apr 19 '17 23:04 alagaccia

Hi drewlag,

Try the following :

use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;

class User extends Eloquent implements AuthenticatableContract,

noel45 avatar Apr 22 '17 11:04 noel45

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.

microwavekonijn avatar May 18 '17 12:05 microwavekonijn

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

NimzyMaina avatar Jun 23 '17 15:06 NimzyMaina

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

Stretsh avatar Nov 12 '17 22:11 Stretsh

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?!

dleber avatar Mar 01 '18 00:03 dleber

This thread also helped me immensely. Cheers @microwavekonijn

mbritton avatar Jul 17 '19 03:07 mbritton

This is not working on laravel 6.2

irving-caamal avatar May 29 '20 16:05 irving-caamal

This is not working on laravel 6.2

Not working for me as well on Laravel 6

kenmush avatar Jul 01 '20 08:07 kenmush

Same issue with Laravel 8

nifunifatralara avatar Nov 26 '20 14:11 nifunifatralara

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

supunbandara avatar Feb 12 '21 06:02 supunbandara

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

The answer has been given here multiple times.

Thanks!

divine avatar Feb 12 '21 06:02 divine