Is there any way of combining these two following routes?

Route::get('project/(:any)', 'dashboard.project@(:1)');
Route::get('project/(:any)/(:any)', 'dashboard.project@(:1)');

I'm asking because the second route, I had to add it in order for the following requests to work:

site.com/project/new => method
site.com/project/view/12351326 => method and parameter
有帮助吗?

解决方案

You can use regex in the first parameter of the get() method to combine those.

See section Regular Expression Route Constraints in the docs.

Something like this might work:

Route::get('project/{name}', function($name)
{
    //
})
->where('name', '[A-Za-z0-9\/]+');

Where the regex will match URLs such as /projects/something/anything. However that might be too loose - it will also match /projects/any/number/of/url/segments. But I believe some more RegEx can help make better constraints to get closer to what you're looking for.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top