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

yeah that makes sense

what if url is

dashboard/movies/funny/../..

got NotFoundHttpException

1 Answer 1

8

Per default a route parameter cannot contain any slashes, because multiple route parameters or segments are separated by slashes.

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

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

However this isn't very elegant nor dynamic and your example suggests there can be many path levels. You can use a where constraint to allow slashes in the route parameter. So this route will basically catch everything that starts with dashboard

Route::get('dashboard/{path?}', function($path= null){
    return $path;
})->where('path', '(.*)');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.