Laravel-mongodb: Compatible with Laravel 5.2?

Created on 24 Jan 2016  路  5Comments  路  Source: jenssegers/laravel-mongodb

I see the record inserted into the collection. However, it fails with the following error. I'm not able to get pass the login screen.

Here's the error:

App\Http\Models\User cannot use Illuminate\Foundation\Auth\User - it is not a trait

Here's my code.

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

class User extends Eloquent
{
    use Authenticatable;

Most helpful comment

Faced same issue with Laravel 5.2, after bit of debugging solve by changing User model.
Modified User model:

namespace App;

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;
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;

class User extends Eloquent implements
    AuthenticatableContract,
    AuthorizableContract,
    CanResetPasswordContract
{
    use Authenticatable, Authorizable, CanResetPassword;
   ........

All 5 comments

Hi ssenaria,

I'm not sure if I accidentally did a composer update or something, but I ended up with the same issue as you despite not making changes (to working code).

My User class is now working with the following:

<?php

namespace App\Models; // this might be just 'App' for you, as I prefer to put it in a folder called models
use Illuminate\Auth\Authenticatable;
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;

class User extends Eloquent implements \Illuminate\Contracts\Auth\Authenticatable
{
    use Authenticatable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

}

Faced same issue with Laravel 5.2, after bit of debugging solve by changing User model.
Modified User model:

namespace App;

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;
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;

class User extends Eloquent implements
    AuthenticatableContract,
    AuthorizableContract,
    CanResetPasswordContract
{
    use Authenticatable, Authorizable, CanResetPassword;
   ........

On laravel 5.3, I just did that and it worked perfectly.

on /vendor/laravel/framework/src/illuminate/Foundation/Auth/user.php

added
use Moloquent\Eloquent\Model as Model;

Like that:

namespace Illuminate\Foundation\Auth;

use Illuminate\Auth\Authenticatable;
use Moloquent\Eloquent\Model as Model;
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 Model implements
    AuthenticatableContract,
    AuthorizableContract,
    CanResetPasswordContract
{
    use Authenticatable, Authorizable, CanResetPassword;
}

Any example for Laravel 5.4 ?

same issue i have used like this

im using laravel 5.5.3 please help

namespace App;
use AppUser;
use IlluminateNotificationsNotifiable;
use IlluminateFoundationAuthUser as Authenticatable;
use JenssegersMongodbEloquentModel as Eloquent;

use DB;

class User extends Authenticatable
{

use Eloquent ;
use Notifiable;

    protected $connection = 'mongodb';
    protected $collection = 'users';
protected $fillable = [
    'name', 'email', 'password',
];


protected $hidden = [
    'password', 'remember_token',
];

}

Was this page helpful?
0 / 5 - 0 ratings