Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 763
Niladri Banerjee - Uttarpara Avatar asked May 22 '18 08:05

Niladri Banerjee - Uttarpara


5 Answers

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
like image 56
foram kantaria Avatar answered Oct 18 '22 23:10

foram kantaria


You must use Authenticatable in User model

for example:

use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
  //your code
}
like image 32
Tina Majd Avatar answered Oct 18 '22 23:10

Tina Majd


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;
like image 21
melih sahin Avatar answered Oct 18 '22 22:10

melih sahin


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

like image 1
nurudeen Avatar answered Oct 18 '22 22:10

nurudeen


use Illuminate\Foundation\Auth\AuthenticatesUsers;

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

like image 1
Vexal Avatar answered Oct 18 '22 22:10

Vexal