Laravel optional prefix routes with regexp

后端 未结 4 970
野的像风
野的像风 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条回答
  •  心在旅途
    2021-01-05 17:22

    You can use a table to define the accepted languages and then:

    Route::group([
        'prefix' => '/{lang?}',
        'where' => ['lang' => 'exists:languages,short_name'],
    ], function() {
    
        // Define Routes Here
    });
    

提交回复
热议问题