由于Guard函数,调用方法尝试不起作用



嘿,伙计们,又是我了对不起,在网上冲浪后,我还没有找到这个错误的答案。我尝试了其他方法,但有些人说需要使用护照,而且我已经编辑了我的auth.php,并添加了一些新的提供商,如"employees">,我还添加了一个保护"employee">

EmployeeLoginroller.php

class EmployeeLoginController extends Controller
{
public function __construct()
{
$this->middleware('guest:employee');
}
public function username(){
return 'empId';
}
public function showLoginForm(){
return view('auth.employee-login');
}
public function login(Request $request){
// Validate the form data
$this->validate($request,[
'empId' => 'required',
'password' => 'required|min:6'
]);
//Store requested data into a variable credentials
$credentials = [
'empId' => $request->input('empId'),
'password' => $request->input('password')
];
// Attempt to log the user in
if(Auth::guard('employee')->attempt($credentials)){
// If successful, redirect to their intended location
return redirect()->intended(route('employee.dashboard'));
}
// If unsuccessful, redirect back to the login with form data
return redirect()->back()->withInput($request->only('empId'));
}
}

这是我的型号

Employee.php

class Employee extends Authenticatable
{
use Notifiable;
protected $guard = 'employee';
protected $table = 'EmpUsersInfo';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'empId', 'password'
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
public function getAuthPassword()
{
return $this->password;
}
}

auth.php

<?php
return [

'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
'hash' => false,
],
'employee' => [
'driver' => 'session',
'provider' => 'employees',
],
'employee-api' => [
'driver' => 'token',
'provider' => 'employees',
'hash' => false,
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => AppUser::class,
],
'employees' => [
'driver' => 'eloquent',
'model' => AppEmployee::class,
],
// 'users' => [
//     'driver' => 'database',
//     'table' => 'users',
// ],
],
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
'throttle' => 60,
],
'employees' => [
'provider' => 'employees',
'table' => 'password_resets',
'expire' => 15,
'throttle' => 60,
],
],
'password_timeout' => 10800,
];

我发现了问题,这是我的凭据,因为我使用了一个没有使用哈希密码的现有数据库,当我输入密码时,它没有成功验证,但没有错误。

最新更新