I saw some people with the same problem but none of the given responses could help me.
I'm currently learning how to use Laravel 5.3 and I have a problem with resources. I've created the following resource in api.php
:
Route::resource('game','GameController',['except' => [
'create','edit'
]]);
So when I call the url laravel.dev/api/game/3
everything works fine, I get my game formatted in JSON :
{
"type": {
"id": 3,
"name": "MMO"
},
"id": 2,
"name": "World of Warcraft"
}
Same thing with a DELETE request, everything works fine.
But when I try to update my game with a PUT or a PATCH request I get the following exception : MethodNotAllowedHttpException .
Here is some more informations that may help you :
Output of the php artisan route:list
command :
POST | api/game | game.store | App\Http\Controllers\GameController@store
GET|HEAD | api/game | game.index | App\Http\Controllers\GameController@index
GET|HEAD | api/game/{game} | game.show | App\Http\Controllers\GameController@show
PUT|PATCH | api/game/{game} | game.update | App\Http\Controllers\GameController@update
DELETE | api/game/{game} | game.destroy | App\Http\Controllers\GameController@destroy
Code used to make the PUT request :
<?php
$client = new http\Client;
$request = new http\Client\Request;
$body = new http\Message\Body;
$body->addForm(array(
'name' => 'Test update'
), NULL);
$request->setRequestUrl('http://laravel.dev/api/game/3');
$request->setRequestMethod('PUT');
$request->setBody($body);
$request->setHeaders(array(
'postman-token' => 'f674324c-936b-58bc-606e-98c085f5e851',
'cache-control' => 'no-cache'
));
$client->enqueue($request)->send();
$response = $client->getResponse();
echo $response->getBody();
I hope you could help me