Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call to a member function parameter() on a non-object in Lumen API

Tags:

api

lumen

I got this error in my Lumen API update user module. I didn't get the Request $request values from postman. It's happening only in my UserController, my other controllers work fine. I'm using the put method to update the user.

This is the error:

FatalErrorException in Request.php line 901: Call to a member function parameter() on a non-object in Lumen API

My update function looks like this:

public function updateUser(Request $request,$user_id)
{
    try {
        $user = User::findOrFail($user_id);

    } catch(ModelNotFoundException $e) {

        return "User not found";
    }
    $user->buyer_id = $request->buyer_id;
like image 655
midhu Avatar asked Jul 21 '16 06:07

midhu


2 Answers

The thing is, Lumen and Laravel use different route resolvers. You can see it for yourself if you just output the type of the variable $route just before that line 901.

Try $request['buyer_id'] instead.

like image 87
alepeino Avatar answered Sep 19 '22 03:09

alepeino


I would suggest to use $request->input('buyer_id'); instead which would not throw any error if the buyer_id doesn't exist on $request stack (if it helps).

We can also pass the default value like this: $request->input('buyer_id', null);

like image 21
rc.adhikari Avatar answered Sep 20 '22 03:09

rc.adhikari