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;
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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With