我为'customer'设置了一个自定义防护,它的LoginController可以正常工作。登录控制器如下:
public function login(Request $request)
{
// Validate form data
$this->validate($request, [
'email' => 'required|email',
'password' => 'required|min:6'
]);
// Attempt to log the user in
if(Auth::guard('customer')->attempt(['email' => $request->email, 'password' => $request->password], $request->remember))
{
return redirect()->intended(route('customer.dashboard'));
}
// if unsuccessful
return redirect()->back()->withInput($request->only('email','remember'))
}
现在,在我的工作流程中,通过另一条途径来结帐客户;我还有另一个控制器,可以在其中创建新客户。然后,由于我掌握了所有详细信息,因此我尝试登录它们,这似乎不起作用,是否有人对我做错的事情有任何了解?
public function registerCustomer($data)
{
$pw = Hash::make($data->pw->main);
$customer = new Customer;
$customer->firstname = $data->customer->name;
$customer->lastname = $data->customer->lastname;
$customer->mobile = $data->customer->mobile;
$customer->email = $data->customer->email;
$customer->password = $pw;
$customer->save();
//I HAVE TRIED THIS
// if(Auth::guard('customer')->attempt(['email' => $data->customer->email, 'password' => $pw]))
// {
// dd('logged in');
// }
//AND NOW THIS...
$logged = Auth::guard('customer')->attempt([ 'email' =>$data->customer->email, 'password' => $pw ]);
dd($logged);
}
在registerCustomer
功能上,$pw
是加密的密码。您不能将其用于Auth::guard('customer')
。您必须替换$pw
为$data->pw->main
。
$logged = Auth::guard('customer')->attempt([ 'email' =>$data->customer->email, 'password' => $data->pw->main ]);
dd($logged);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句