Prakhar Prakhar - 28 days ago 15
PHP Question

Laravel routing issue

I am using

laravel
framework. I've setup couple of
routes
that take a parameter like
example.com/route/{dir_name}
. When I pass in a dir which has childrens it considers it as another route. Is there a way to bypass it?

I'm using this code:

Route::get('/route/something/{path}',array('as'=>'something',function($path){
return $path;
}));


When I use
/route/something/home/user/dev
it throws a
Symfony\Component\HttpKernel\ Exception\NotFoundHttpException
exception.

Answer

You can try using constraints on the route parameter with a regular expression.

Route::any('/route/{dir_name}', function ($dir_name) {
    return $dir_name;
})->where('dir_name', '.*');

See the docs section about route parameters, specifically the "Regular Expression Route Constraints" part.