尝试运行以下代码时出现错误
我得到的错误。
Fatal error: Can't use method return value in write context in Lumen 5.2.
在“我的路线”中:
$app->post('oauth/access_token', function(Request $request) {
$userverify=User::Where('username',$_POST['username'])->orWhere('email',$_POST['username'])->first();
if($userverify){
$request->input('username')=$userverify->email;
}
$json = array();
try{
$json = Authorizer::issueAccessToken();
}catch (Exception $e){
$json['error'] = 'invalid_credentials';
$json['error_description'] = 'The user credentials were incorrect';
}
return response()->json($json);
});
谢谢。
答案 0 :(得分:1)
此错误是因为您正在此处为函数的return语句分配值:
$request->input('username') = $userverify->email;
$ request-> input()用于仅检索请求值而不设置它们。
如果您仍想向请求中添加一些值,则可以尝试使用以下方法:
// Add a value to the request
$request->request->add(['username' => $userverify->email]);
// Set a value in request
$request->request->set('username', $userverify->email);
希望这会有所帮助。