I have written some REST API Methods, including one for updating a DB entry:
// Update
public function update(CreateAEDRequest $request, $id) {
$aed = AED::find($id);
if(!$aed) {
return response()->json(['message' => "Dieser AED exisitiert nicht", 'code' => 404], 404);
}
$owner = $request->get('owner');
$street = $request->get('street');
$aed->owner = $owner;
$street->street = $street;
$aed->save();
return response()->json(['message' => 'Der AED wurde aktualisiert'], 200);
}
The Route is defined as:
Route::put('/aeds/{aeds}', 'APIAEDController@update');
Route::patch('/aeds/{aeds}', 'APIAEDController@update');
A Request is being handled by:
<?php
namespace App\Http\Requests;
use App\Http\Requests\Request;
use Illuminate\Http\JsonResponse;
class CreateAEDRequest extends Request
{
public function authorize()
{
// turn back to false when doing auth
return true;
}
public function rules()
{
return [
'owner' => 'required',
'street' => 'required'
];
}
}
But when I use postman and try to update the existing DB entry and I fill in the owner and street variable to be sent in POSTMAN as requested, I get the message: "Could not get any response. Returns Status Code 0"
All the other methods work fine. Is the definition of my routing not correct?
Update
When I send the data as x-www-form-urlencoded
it works! When I send them as form-data it brings up the error message.
In
Postman
POST
_method
with valuePUT
orPATCH