Hi guys!
Recently I added a "page" segment on the url for pagination so I changed my '{section}' route to '{section}/{page?}/{pageCount?}. I wanted it to be optional so /games will just point to the first page and /games/page/2 will point to the second page. The problem is adding { } will cause it to be passed on a controller function so now my controller function looks like this:
function index($section, $page, $pageCount){
// do something here
}
I only want to pass the section and the pageCount in the controller function and the other problem is how can I set a default value for the pageCount when I'm using this kind of route setting
Route::get(
'/{section}',
array(
'as' => 'route.post',
'uses' => 'PostController@index',
)
)
->where(
array(
'section' => '(games|guides|cheats)'
)
);
Thanks in advance!
Set up two routes, one without pagination and another with it.
Route::get( '{section}', array(
'as' => 'route.post',
'uses' => 'PostController@index',
))->where(array(
'section' => '(games|guides|cheats)'
));
Route::get( '{section}/page/{pageCount}', array(
'as' => 'route.post.paged',
'uses' => 'PostController@index',
))->where(array(
'section' => '(games|guides|cheats)'
));
then in your controller define the default pageCount
function index($section, $pageCount = 1){
// do something here
}
@spescina Toying with routes yesterday I ended up with this kind of solution, glad to know that someone else ended up with this solution. Thanks!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community