Laravel 4 route with unlimited number of parameters

后端 未结 2 1292
-上瘾入骨i
-上瘾入骨i 2021-01-02 05:19

I\'m trying to create a dynamic route for an unlimited number of URL levels.

Here\'s my current route

Route::get(\'{pageLink}\', array(\'uses\' =>         


        
2条回答
  •  -上瘾入骨i
    2021-01-02 05:55

    You can try something like this:

    //routes.php
    Route::get('{pageLink}/{otherLinks?}', 'SiteController@getPage')->where('otherLinks', '(.*)');
    

    Remember to put the above on the very end (bottom) of routes.php file as it is like a 'catch all' route, so you have to have all the 'more specific' routes defined first.

    //controller 
    class SiteController extends BaseController {
    
        public function getPage($pageLink, $otherLinks = null)
        {
            if($otherLinks) 
            {
                $otherLinks = explode('/', $otherLinks);
                //do stuff 
            }
        }
    
    }
    

    This approach should let you use unlimited amount of params, so this is what you seem to need.

提交回复
热议问题