brazorf
brazorf

Reputation: 1951

Laravel4 Routing issue with controllers

// 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

Why do in last 2 cases request is not routed to multiple/any method? How's the router logic in this case?

Upvotes: 0

Views: 71

Answers (1)

mpj
mpj

Reputation: 5367

I think you have two options here.

First one, is specifying your controller actions in your routes. Note that I'm using Route::get() and @action:

Route::get('api/v1/offer/{id}/choice/multiple', 'restful\OfferController@multiple');
Route::get('api/v1/offer/{id}/choice/any', 'restful\OfferController@any');

Second, let Laravel to wire any api/v1/offer/{id}/choice to OfferController:

Route::controller('api/v1/offer/{id}/choice', 'restful\OfferController');

If you use this second option, you have to define your actions like this in your controller (assuming they are GET requests):

class OfferController extends BaseController {

    public function getMultiple()
    {
        //
    }

    public function getAny()
    {
        //
    }


}

Upvotes: 2

Related Questions