尝试多用户身份验证时,它一直在说传递了错误的参数实例

时间:2019-04-11 03:32:34

标签: laravel-5.7 laravel-authentication

我在尝试使用守卫登录多个用户并且无法理解需要传递哪个实例时遇到此错误:

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

这是我的身份验证控制器:

<?php 
namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;

class EmploysLoginController  extends Controller
{
 use AuthenticatesUsers;

 protected $guard = 'Employs';
/**

 * Where to redirect users after login.

 *

 * @var string

 */

protected $redirectTo = '/Employs';

/**

 * Create a new controller instance.

 *

 * @return void

 */

public function __construct()
{
    $this->middleware('guest')->except('logout');
}

public function showLoginForm()
{
    return view('auth.employe-login');
}

public function login(Request $request)
{

    if (auth()->guard('Employs')->attempt(['email' => $request->email, 'password' => $request->password])) {

        dd(auth()->guard('Employs')->user());
    }

    return back()->withErrors(['email' => 'Email or password are wrong.']);
 }
}

这是我的模特:

<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Authenticatable;
// use Illuminate\Contracts\Auth\Authenticatable as 
AuthenticatableContract;

class Employs extends Model// implements AuthenticatableContract 
{
  protected $primaryKey = 'employ_id';
}

我尝试了许多在线/堆栈溢出提供的解决方案,但我一直在收到此错误,如果您发现此问题有歧义,请在进行否决表决之前询问,我最后一次在此处进行尝试。

1 个答案:

答案 0 :(得分:2)

您应该创建一个这样的模型:

模型

value="{{item.id}}_{{item.childId}}">

我希望这项工作对您有用。