Laravel 5.5 Type error: Argument 1 passed to Illuminate\Auth\EloquentUserProvider::validateCredentials() must be an instance

In my LoginController under Auth, I have used the following codes:

namespace App\Http\Controllers\Auth;

use App\Model\Admin;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Redirect;
use Hash;
use Auth;
use DB;
use App\Model\UserAdmin;

class LoginController extends Controller {
use AuthenticatesUsers;
public function __construct() {
        $this->middleware('guest')->except('logout');
    }

public function doLogin(Request $request) {
$userdata = array(
            'email' => Input::get('email'),
            'password' => Input::get('password'),
            'status' => '1',
        );
if (Auth::guard('admin')->attempt($userdata)) {
  return Redirect::intended('/administrator/dashboard')->with('successMessage', 'You have successfully logged in.');
}
}
}

And in UserAdmin (model) under app/Model is as follows:

namespace App\Model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Config;
class UserAdmin extends Authenticatable {
protected $table = 'adminusers';
    public $timestamps = false;
    protected $fillable = ['firstName', 'lastName', 'email', 'company', 'website'];

    public function __construct() {
        parent::__construct(); // Don't forget this, you'll never know what's being done in the constructor of the parent class you extended
    }

}

After submitting the login details, it shows me the error:

Type error: Argument 1 passed to Illuminate\Auth\EloquentUserProvider::validateCredentials() must be an instance of Illuminate\Contracts\Auth\Authenticatable, instance of App\Model\UserAdmin given, called in /var/www/html/XXXXXX/vendor/laravel/framework/src/Illuminate/Auth/SessionGuard.php on line 379

Upvotes: 18

Views: 47447

Answers (7)

Martin Mbae
Martin Mbae

Reputation: 1266

Go to your Model and instead of extending Model, extend User

<?php

namespace App;


class Staff extends \Illuminate\Foundation\Auth\User
{
}

Upvotes: 0

Anish Rajendran
Anish Rajendran

Reputation: 21

You must extends Authenticatable class and implements JWTSubject in User model

For example :

class User extends Authenticatable implements JWTSubject {

Upvotes: 2

Tina Majd
Tina Majd

Reputation: 161

You must use Authenticatable in User model

for example:

use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
  //your code
}

Upvotes: 16

Vexal
Vexal

Reputation: 804

use Illuminate\Foundation\Auth\AuthenticatesUsers;

Then in your model class, extends AuthenticatesUsers instead of Model.

Upvotes: 1

melih sahin
melih sahin

Reputation: 781

You must declared use AuthenticableTrait for Authenticatable interface.

For example :

use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Auth\Authenticatable as AuthenticableTrait;
use Illuminate\Database\Eloquent\Model;

class Company extends Model implements Authenticatable
{
use AuthenticableTrait;

Upvotes: 6

nurudeen
nurudeen

Reputation: 11

Try and run 'composer dump-autoload' to check for "ambiguous User class resolution". It is likely you have two classes Defined as User Class.

Upvotes: 1

foram kantaria
foram kantaria

Reputation: 786

I suppose that you required to add implements \Illuminate\Contracts\Auth\Authenticatable to your UserAdmin model class definition.

    class UserAdmin extends Model implements 
    \Illuminate\Contracts\Auth\Authenticatable

Upvotes: 42

Related Questions