Search code examples
phplaravellumenlumen-5.2

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


I got error when I try to run the following code Error I am getting. Fatal error: Can't use method return value in write context in Lumen 5.2.

In My Route :

$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);
    });

Thanks beforehand.


Solution

  • This error is because you're assigning a value to a function's return statement right here:

    $request->input('username') = $userverify->email;
    

    $request->input() is used to only retrieve the request values and not to set them.

    If you still want to add some values to the request, then you might try using the following approach:

    // Add a value to the request
    $request->request->add(['username' => $userverify->email]);
    
    // Set a value in request
    $request->request->set('username', $userverify->email);
    

    Hope this helps.