Match a string against a route

138 views Asked by At

Is there a method in Laravel 5 to which I give the following string projects/1/files and it tells me if it matches the route projects/{id}/files?

1

There are 1 answers

3
Bishal Paudel On

Use route patterns:

Route::pattern('id', '[0-9]+'); //matches 0-9 
Route::get('projects/{id}/files', 'controller@method');

Another example:

Route::pattern('slug', '[a-z0-9-]+'); //matches a-z, 0-9 and '-'
Route::get('projects/{slug}/files', 'controller@method');