[英]Laravel Auth::guard('employee')->attempt not working
[英]Calling Method Attempt Not Working Due to Guard Function
嘿伙計們,我再次抱歉,上網后,我還沒有找到這個錯誤的答案。 我嘗試了其他事情,但有些人說需要使用護照,而且我已經編輯了我的 auth.php 並添加了一些新的提供者,例如“員工” ,我還添加了一個警衛“員工”
EmployeeLoginController.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'));
}
}
這是我的 model
員工.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' => App\User::class,
],
'employees' => [
'driver' => 'eloquent',
'model' => App\Employee::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,
];
我發現了問題,這是我的憑據,因為我使用了一個未使用 hash 密碼的現有數據庫,當我輸入密碼時,它沒有成功通過身份驗證,但沒有錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.