Search code examples
laravelurl-routing

Unable to fetch get parameter with encoded '/' in Laravel using route


I am new to Laravel and working on existing code.

I want to pass some values in url in format of URL/val1/val2/val3.

Every thing is working perfect if all values with normal string or number

but if any value has special character like slash / or \ it shows errors.

eg. working :- URL/abc/pqr/xys

but if val3 = 22/06 ;url is URL/val1/val2/22/06 error shows 404 not found

If I encoded val3 using javaScript's function encodeURIComponent()

val3=22%2F06 and url become URL/val1/val2/22%2F06 shows Object not found!

 // My current route web.php is:-

    Route::get('/export/{name}/{status}/{search}', 'ReportController@export')->name('export');

Solution

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