Domanda

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
È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top