0

I'm having trouble to get my controller to listen to DELETE requests. When I send a DELETE request to /api/players/1 I get a NotFoundHttpException. Here's my routes.php

Route::group(array('prefix' => 'api'), function() {

    Route::controller('matches', 'MatchController');
    Route::controller('players', 'PlayerController');
    Route::controller('auth', 'AuthController');

});

My PlayerController

class PlayerController extends BaseController {

    public function getIndex() {
        // do something... this works
    }

    public function postIndex() {
        // do something... this works
    }

    public function deleteIndex() {
        // works when I send a DELETE request to /api/players
    }

    public function delete($id = null) {
        // doesn't work!
    }
}

I guess I'm missing some kind of secret word or something... I just don't know how to catch a DELETE request with an id. What am I doing wrong?

thomasjonas
  • 460
  • 1
  • 5
  • 18

1 Answers1

1

Ok... So now I've changed my controller to a resource controller... I'm not completely sure if that is the correct way to do it but it seems to work!

New routes.php:

Route::group(array('prefix' => 'api'), function() {

    Route::resource('matches', 'MatchController');
    Route::resource('players', 'PlayerController');
    Route::resource('auth', 'AuthController');

});

PlayerController.php:

class PlayerController extends BaseController {

    public function index() {
        // GET /api/players
    }

    public function store() {
        // POST /api/players
    }

    public function destroy($id) {
        // DELETE /api/players/{id}
    }
}
thomasjonas
  • 460
  • 1
  • 5
  • 18