0

我无法让我的控制器收听 DELETE 请求。当我向 /api/players/1 发送 DELETE 请求时,我得到了 NotFoundHttpException。这是我的 routes.php

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

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

});

我的播放器控制器

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!
    }
}

我想我错过了某种秘密词或其他东西......我只是不知道如何捕捉带有 id 的 DELETE 请求。我究竟做错了什么?

4

1 回答 1

1

好的...所以现在我将控制器更改为资源控制器...我不完全确定这是否是正确的方法,但它似乎有效!

新路线.php:

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

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

});

播放器控制器.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}
    }
}
于 2013-03-21T21:52:47.960 回答