在我的laravel应用程序中,我需要登录<CreateAssignmentModal {...this.props} />
表。所以,我做了customers
。
我的CustomerLoginController
看起来像是:
CustomerLoginController
我在class CustomerLoginController extends Controller
{
public function login(Request $request)
{
// Validate the data
$this->validate($request,[
'email' => 'required|email',
'password' => 'required'
]);
$credentials=[
'email' => $request->get('email'),
'password' => $request->get('password')
];
// Log The Customer In
if (Auth::guard('customer')->attempt(['email'=> $request['email'],'password' => $request['password']]))
{
// If Authentication passed...
dd($credentials);
return redirect(route('first'));
}
// If Authentication not successful, redirect back to login form with the inputs
return redirect()->back()
->withInput($request->only($this->username()));
}
public function username()
{
return 'email';
}
中设置了customer
警卫和提供者。我的config/Auth.php
文件:
config/Auth.php
问题是即使凭据正确,登录尝试也总是不成功。
我错过了什么?
答案 0 :(得分:0)
那么客户模型呢。
它应该像User Model一样扩展Authenticatable。
class User extends Authenticatable
{
/* your code */
}
class Customer extends Authenticatable
/* your code */
{
}
并且不要忘记在模型中使用Authenticatable。 :)
use Illuminate\Foundation\Auth\User as Authenticatable;