I am developing a laravel api and sucessfully made gets, posts, deletes and i am now trying to do the update method using PATCH.
Here is my first try:
public function update($id, Request $request)
{
$taxes = taxes::find($id);
$taxes ->fill($request->only(['$request']));
$taxes->save();
}
And testing it with the follow url on postman
****.local/api/taxes/1?description=test
This obviously doesnt work, i tought i would be able to see the error but i am currently on a different machine but hopefully someone can guide me to correct path to make this update method.
Dont forget its an api, no views/forms.
Thank you.
You have to specify the body of the query (so the variables you want to change) in the x-www-form-urlencoded
tab of the Body
tab for your request in Postman.
You can find a screenshot here: http://img11.hostingpics.net/pics/987644Sanstitre1.jpg (waiting for imgur to be back online)
You also have an issue in your method, your code should be the following:
public function update($id, Request $request)
{
$taxes = taxes::find($id);
$taxes ->fill($request->only(['description', 'anyotherfield', '...']));
$taxes->save();
}
Could be to do with this line: $request->only(['$request'])
, as your request is unlikely to have a parameter called $request
. You might've been meaning to use $request->all()
(all input) or $request->only('description', 'etc.')
which will whitelist given paramters.
Probably should give your model a singular name, and capitalize it.
Tax::findOrFail($id)->update($request->only('description'))