// My routes
Route::controller('api/v1/offer/{id?}', 'restful\OfferController');
Route::controller('api/v1/offer/{id}/qualifiers', 'restful\OfferController');
Route::controller('api/v1/offer/{id}/dishes', 'restful\OfferController');
Route::controller('api/v1/offer/{id}/choice/multiple', 'restful\OfferController');
Route::controller('api/v1/offer/{id}/choice/any', 'restful\OfferController');
// These works fine to me
'api/v1/offer/{id?}' -> properly routes to OfferController::getIndex
'api/v1/offer/{id}/qualifiers' -> properly routes to OfferController::getQualifiers
'api/v1/offer/{id}/dishes' -> properly routes to OfferController::getDishes
// ... but here i have problems.
'api/v1/offer/{id}/choice/multiple' -> routes to OfferController::choice
'api/v1/offer/{id}/choice/any' -> routes to OfferController::choice
为什么在最后2个案例中请求没有路由到多个/任何方法?在这种情况下,路由器逻辑如何?
答案 0 :(得分:2)
我认为你有两种选择。
首先,在路线中指定控制器动作。请注意,我使用的是Route::get()
和@action
:
Route::get('api/v1/offer/{id}/choice/multiple', 'restful\OfferController@multiple');
Route::get('api/v1/offer/{id}/choice/any', 'restful\OfferController@any');
其次,让Laravel将任何api/v1/offer/{id}/choice
连接到OfferController
:
Route::controller('api/v1/offer/{id}/choice', 'restful\OfferController');
如果您使用第二个选项,则必须在控制器中定义这样的操作(假设它们是GET
个请求):
class OfferController extends BaseController {
public function getMultiple()
{
//
}
public function getAny()
{
//
}
}