PHP Fatal error: Can't use method return value in write context in Lumen 5.2

PHP Fatal error: Can't use method return value in write context in Lumen 5.2

当我尝试 运行 以下代码时出现错误 我得到的错误。 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);
    });

先谢谢了。

此错误是因为您在此处为函数的 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);

希望对您有所帮助。