How to define a Laravel route with a parameter that contains a slash character

Add the below catch-all route to the bottom of your routes.php and remember to run composer dump-autoload afterwards. Notice the use of “->where” that specifies the possible content of params, enabling you to use a param containing a slash.

Route::get('view/{slashData?}', 'ExampleController@getData')
    ->where('slashData', '(.*)');

And than in your controller you just handle the data as you’d normally do (like it didnt contain the slash).

class ExampleController extends BaseController {

    public function getData($slashData = null)
            //do stuff 


This should work for you.

Additionally, here you have detailed Laravel docs on route parameters: [ docs ]

Leave a Comment