2

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

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';
}

我尝试了许多在线/stackoverflow 提供的解决方案,但我不断收到此错误,如果您发现此问题有歧义,请在投反对票之前询问,我上次在这里尝试过。

4

1 回答 1

2

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

模型

    <?php

        namespace App;

        use Illuminate\Notifications\Notifiable;
        use Illuminate\Foundation\Auth\User as Authenticatable;

        class Employs extends Authenticatable
        {
            use Notifiable;

            protected $guard = 'Employs';

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

            /**
             * The attributes that should be hidden for arrays.
             *
             * @var array
             */
            protected $hidden = [
                'password', 'remember_token',
            ];
        }

我希望这对你有用。

于 2019-04-11T05:15:42.937 回答