Jamie
Jamie

Reputation: 10886

Laravel routing with resource

Currently my routes file looks like this:

Route::get('/corporation/{paginate}','Corporation\CorporationController@index');

Route::group(['middleware' => ['active']], function () {

    /* Corporation */
    Route::resource('corporation','Corporation\CorporationController');

}

So I would expect that when I go to /corporation I'would not use the resource route. But it does -_-

How can I make sure that it uses the first route?

Many thanks!

--EDIT--

Route::post('/user', 'User\UserController@store');

Route::group(['middleware' => ['active']], function () {

    /* User */
    Route::resource('user', 'User\UserController');
}

Upvotes: 0

Views: 156

Answers (1)

Carlos
Carlos

Reputation: 1321

Its going to use the resource route because /corporation does not meet the standards of /corporation/{paginate}.

Since im guessing you want /corporation/{paginate} to be optional and use resource routes for the rest of the urls, you should make paginate optional by adding a ? sign.

Route::get('/corporation/{paginate?}', 'Corporation\CorporationController@index');

Aditionaly you would need to exclude the default GET /corporation from the resources.

Route::resource('corporation', 'Corporation\CorporationController', ['except' => [
    'index'
]]);

Upvotes: 1

Related Questions