Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 电话号码和密码为Laravel/Lumen Tymon/JWT_Php_Laravel_Jwt_Lumen - Fatal编程技术网

Php 电话号码和密码为Laravel/Lumen Tymon/JWT

Php 电话号码和密码为Laravel/Lumen Tymon/JWT,php,laravel,jwt,lumen,Php,Laravel,Jwt,Lumen,我正在使用JWT为我的API应用程序创建一个API登录。在默认代码中,JWT使用电子邮件和密码进行身份验证 public function login(Request $request){ $credentials = $request->only(['email', 'password']); if (!$token = JWTAuth::attempt($credentials)) { return 'Invalid login details';

我正在使用JWT为我的API应用程序创建一个API登录。在默认代码中,JWT使用电子邮件和密码进行身份验证

public function login(Request $request){
    $credentials = $request->only(['email', 'password']);

    if (!$token = JWTAuth::attempt($credentials)) {
      return 'Invalid login details';
    }
    return $token;
}
但是现在,我想通过电话/电子邮件密码进行登录,这意味着,当请求到来时,我将使用正则表达式来识别电子邮件或电话。然后,使用这是trunt()函数的凭据


有什么解决办法吗?提前感谢。

我发现请求是lighted\Http\Request; 和
Request->only()
返回数组

您可以使用获取或设置值
$credentials[“email”]
$credentials[“password”]

您可以通过将电话或电子邮件作为凭据发送来轻松完成此操作

if($regexShowsItsAnEmail) {
    $credentials = $request->only(['email', 'password']); // or simply $credentials = ['email' => $email, 'password' => $password]
} elseif($regexShowsItsAPhoneNumber) {
    $credentials = $request->only(['phone', 'password']); // or simply $credentials = ['phone' => $phone, 'password' => $password]
} else {
    return response()->json(['message' => 'Unauthorized'], 401);
}