我有两个表用于管理和客户端,每种类型的用户使用两种不同的登录方法。我已经为管理使用了try()方法。我正在尝试为客户端创建JWTAuthentication。在这一刻,当我试图认证客户端登录,laravel查询内管理表,而我希望它查询内客户端表。我试图设置配置来专门研究客户端模型。但它仍在调查行政部门。
我如何告诉laravel,以避免查看管理表,当客户端试图登录?
if($dbPass==$password)
{
//find secret api key and send it to curl
//$this->callTeamworkApi($query->secretApiKey);
//set session
//JWT authenticate
//$credentials = ["email"=>$email,"password"=>$password];
//$credentials = $request->all('email','password');
$credentials =[];
$credentials['email'] = $email;
$credentials['password'] = $request->password;
try{
'Config::set('auth.model', 'Client');
'Config::set( 'auth.table' , 'clients' );
if( ! $token = JWTAuth::attempt($credentials))
{
return response()->json([
'response' => 'Some error with user credentials'
]);
}else{
// $request->session()->put('secretApiKey', $query->secretApiKey);
// $request->session()->put('userEmail', $sessionEmail);
// $request->session()->put('userId', $sessionId);
// $request->session()->put('userName', $sessionName);
// $request->session()->put('timeCreated', $timeCreated);
//find user details and put them inside session array
$msg = "Login_checked";
return response()->json(["token"=>compact('token'), "msg"=> $msg]);
}
}catch(JWTExceptions $err){
return response()->json(['response'=>$err]);
}
}else{
$msg = "Password_wrong";
}
所有身份验证驱动程序都有一个用户提供程序。这定义了如何从数据库或应用程序使用的其他存储机制中检索用户,以持久化用户数据。
如果你有多个用户表或模型,你应该配置多个代表每个模型/表的源。
这应该在config/auth.php
文件中完成。
'providers' => [
'admins' => [
'driver' => 'eloquent',
'model' => App'Admin::class,
],
'clients' => [
'driver' => 'eloquent',
'model' => App'Client::class,
],
],
这在Laravel 5中可以工作,我不确定版本4和以下。