Laravel if statement for request object
Solution 1
Do this instead:
if($request->has('storeid')) {
...
Solution 2
The error "Call to a member function parameter() on a non-object" is not because you are not including the "storeid" input, but because you are not calling an instance of the Store object.
Maybe if you do something like:
if(isset($request->storeid))
$store = Store::findOrFail($request->storeid)
Citti
Updated on June 15, 2022Comments
-
Citti almost 2 years
Currently building out an API. I am working on an update function with excepts the incoming request. so: api.dev.com/?api_key=asdf&storeid=2 etc
now in the backend i am accepting the Request and then i am trying to write some logic to check if the request includes storeid then update that entry etc.
But when i am writing my logic and i do
if(isset($request->storeid)) $store->id = $request->storeid;
If I do not include storeid in my put request then i get:
Call to a member function parameter() on a non-object
Because it is not present. Am I approaching writing this logic the wrong way?
I want to leave it up to the users to update the records they want. So they should not have to include all the variables in the request. Just those that need to be updated.
Citti