Laravel 5.5 类型错误:传递给 Illuminate\Auth\EloquentUserProvider::validateCredentials() 的参数 1 必须是一个实例
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/50463155/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5.5 Type error: Argument 1 passed to Illuminate\Auth\EloquentUserProvider::validateCredentials() must be an instance
提问by Niladri Banerjee - Uttarpara
In my LoginController under Auth, I have used the following codes:
在 Auth 下的 LoginController 中,我使用了以下代码:
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:
而在App/Model下的UserAdmin(model)如下:
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
类型错误:传递给 Illuminate\Auth\EloquentUserProvider::validateCredentials() 的参数 1 必须是 Illuminate\Contracts\Auth\Authenticatable 的实例,App\Model\UserAdmin 的实例,在 /var/www/html/XXXXXX/ 中调用供应商/laravel/framework/src/Illuminate/Auth/SessionGuard.php 在线 379
回答by foram kantaria
I suppose that you required to add implements \Illuminate\Contracts\Auth\Authenticatable to your UserAdmin model class definition.
我想您需要将 implements \Illuminate\Contracts\Auth\Authenticatable 添加到您的 UserAdmin 模型类定义中。
class UserAdmin extends Model implements
\Illuminate\Contracts\Auth\Authenticatable
回答by Tina Majd
You must use Authenticatable in User model
您必须在 User 模型中使用 Authenticatable
for example:
例如:
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
//your code
}
回答by nurudeen
Try and run 'composer dump-autoload' to check for "ambiguous User class resolution". It is likely you have two classes Defined as User Class.
尝试运行“composer dump-autoload”来检查“不明确的用户类解析”。您可能有两个定义为用户类的类。
回答by melih sahin
You must declared use AuthenticableTrait for Authenticatable interface.
您必须声明 use AuthenticableTrait for Authenticatable 接口。
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;
回答by Sourn Visal
use Illuminate\Foundation\Auth\AuthenticatesUsers;
使用 Illuminate\Foundation\Auth\AuthenticatesUsers;
Then in your model class, extends AuthenticatesUsers
instead of Model
.
然后在您的模型类中,扩展AuthenticatesUsers
而不是Model
.
回答by Anish Rajendran
You must extends Authenticatable class and implements JWTSubject in User model
您必须扩展 Authenticatable 类并在 User 模型中实现 JWTSubject
For example :
例如 :
class User extends Authenticatable implements JWTSubject {