删除Laravel路由中的HTTP方法

时间:2015-08-29 13:02:52

标签: php laravel laravel-5.1

我使用Laravel资源路由(通过控制器)。这是路由代码

Route::resource( 'difficulty', 'DifficultyController', [ 'only' => [ 'index', 'show', 'update', 'create' ] ] );

以下是创建的路线

+--------+----------+-------------------------+-------------------+--------------------------------------------------+------------+
| Domain | Method   | URI                     | Name              | Action                                           | Middleware |
+--------+----------+-------------------------+-------------------+--------------------------------------------------+------------+
|        | GET|HEAD | difficulty              | difficulty.index  | App\Http\Controllers\DifficultyController@index  |            |
|        | GET|HEAD | difficulty/create       | difficulty.create | App\Http\Controllers\DifficultyController@create |            |
|        | PATCH    | difficulty/{difficulty} |                   | App\Http\Controllers\DifficultyController@update |            |
|        | GET|HEAD | difficulty/{difficulty} | difficulty.show   | App\Http\Controllers\DifficultyController@show   |            |
|        | PUT      | difficulty/{difficulty} | difficulty.update | App\Http\Controllers\DifficultyController@update |            |
+--------+----------+-------------------------+-------------------+--------------------------------------------------+------------+

它工作正常,除了我不需要" HEAD"和" PATCH"方法,我想删除它们。因此列出路线将显示以下内容

+--------+----------+-------------------------+-------------------+--------------------------------------------------+------------+
| Domain | Method   | URI                     | Name              | Action                                           | Middleware |
+--------+----------+-------------------------+-------------------+--------------------------------------------------+------------+
|        | GET      | difficulty              | difficulty.index  | App\Http\Controllers\DifficultyController@index  |            |
|        | GET      | difficulty/create       | difficulty.create | App\Http\Controllers\DifficultyController@create |            |
|        | GET      | difficulty/{difficulty} | difficulty.show   | App\Http\Controllers\DifficultyController@show   |            |
|        | PUT      | difficulty/{difficulty} | difficulty.update | App\Http\Controllers\DifficultyController@update |            |
+--------+----------+-------------------------+-------------------+--------------------------------------------------+------------+

有可能吗?我使用的是Laravel 5.1

1 个答案:

答案 0 :(得分:1)

如何进行显式声明?

Route::get('/difficulty','DifficultyController@index');
Route::get('/difficulty/create','DifficultyController@create');
Route::get('/difficulty/{difficulty}','DifficultyController@show');
Route::put('/difficulty/{difficulty}','DifficultyController@update');

我甚至更喜欢这样,因为它可以更清楚地了解您的应用程序的功能。