Laravel optional prefix routes with regexp

后端 未结 4 981
野的像风
野的像风 2021-01-05 16:48

Is there a way to create routes with prefixes so I can have routes like this

/articles.html -> goes to listing  Controller in default language
/en/article         


        
4条回答
  •  萌比男神i
    2021-01-05 17:34

    Another working solution would be to create an array of langs and loop over it:

    $langs = ['en', 'fr', ''];
    
    foreach($langs as $lang) {
      Route::get($lang . "/articles", "SomeController@someMethod");
    }
    

    For sure this makes your route file less readable, however you may use php artisan route:list to clearly list your routes.

提交回复
热议问题