我有点不确定如何正确构建我的帖子路线。在我的大多数路线中,我一直在路线的末尾添加一个“过程”。
Route::get('auth/notes/{note}/delete','Auth\NotesController@delete');
Route::post('auth/notes/{note}/delete/process','Auth\NotesController@processDelete');
有时我只是把它和GET路线一样
//EDIT USER
Route::get('users/{user}/edit','AdminUserController@editUser');
Route::post('users/{user}/edit','AdminUserController@editUserProcess');
这有点不一致,我希望将来的代码尽可能易于阅读和理解。
在laravel中定义POST路由有没有明确正确的方法?
答案 0 :(得分:0)
您可以使用资源路由,如下所示:
Route::resource('customer', 'Api\V1\CustomerController');
这会给你这样的路线:
| GET|HEAD | api/v1/customer | api.v1.customer.index | App\Http\Controllers\Api\V1\CustomerController@index
| POST | api/v1/customer | api.v1.customer.store | App\Http\Controllers\Api\V1\CustomerController@store
| GET|HEAD | api/v1/customer/{customer}| api.v1.customer.show | App\Http\Controllers\Api\V1\CustomerController@show
| DELETE | api/v1/customer/{customer}| api.v1.customer.destroy | App\Http\Controllers\Api\V1\CustomerController@destroy
......等等。
见这里:
https://laravel.com/docs/5.2/controllers#restful-resource-controllers