Laravel additional route parameters

Route::get('dashboard/{path?}', function($path= null)
{
    return $path;
});

      

yes that makes sense

what if url

dashboard/movies/funny/../..

got NotFoundHttpException

0


source to share


1 answer


By default, the route parameter cannot contain any forward slashes, because multiple route parameters or segments are separated by slashes.

If you have a finite number of path levels, you can do this:

Route::get('dashboard/{path1?}/{path2?}/{path3?}', function($path1 = null, $path2 = null, $path3 = null)

      



However, this is not very elegant and dynamic, and your example hints that there can be many levels of the path. You can use a where constraint to allow slashes in the route parameter. So this route will basically catch anything that starts withdashboard

Route::get('dashboard/{path?}', function($path= null){
    return $path;
})->where('path', '(.*)');

      

+7


source







All Articles