For my website I want to have 2 guards: employee and customer. When I login or register, I always get 302. When I do the login of an employee:
Auth::guard('employee')->attempt(['username' => $request->username, 'password' => $request->password])
I get false. I have checked $request and the values are right. When I do the same thing without the guard, I get an error that he can't find username in users. So he uses the guard to search in the right column but still, he doesn't find it there. The values of username and password are in the database. But, when I seeded it, it wasn't hashed because I'm just a student and it's all in test environment. Could that be a problem? I haven't posted here the middleware and all that stuff because when I do dd() of the line code above, I get "false" so is there a problem that the atttempt or does it really need middleware this line of code?
My employee model looks like this:
class Employee extends Authenticatable {
use Notifiable;
protected $guard = 'employee';
protected $fillable = [
'name', 'username', 'password',
];
protected $hidden = [
'password', 'remember_token',
]; }
The auth.php (short version)
'guards' => [
'employee' => [
'driver' => 'session',
'provider' => 'employees',
],
'customer' => [
'driver' => 'session',
'provider' => 'customers',
]
],
'providers' => [
'employees' => [
'driver' => 'eloquent',
'model' => App\Employee::class,
],
'customers' => [
'driver' => 'eloquent',
'model' => App\Customer::class,
],
My loginController
public function __construct()
{
$this->middleware('guest')->except('logout');
$this->middleware('guest:employee')->except('logout');
$this->middleware('guest:customer')->except('logout');
}
public function adminLogin(Request $request)
{
$this->validate($request, [
'username' => 'required',
'password' => 'required|min:6'
]);
if (Auth::guard('employee')->attempt(['username' => $request->username, 'password' => $request->password])) {
return redirect()->intended('/employee/overview');
}
return back()->withInput($request->only('username'));
}
I know that the question is asked a lot but I have searched a lot didn't find the solution and asked my web teacher but he also didn't find the problem. I could maybe use somethings with roles but I find it stupid that I cannot to it. I just want to learn to use guards correctly.
Thank you in advance!
The problem is your password must hash in datebase
use function
$password=bcrypt($request['password']);
or
Hash::make($data['password'])