0

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');
Satish
  • 696
  • 1
  • 11
  • 22
  • 1
    You can use this as a solution: https://stackoverflow.com/questions/21552604/how-to-define-a-laravel-route-with-a-parameter-that-contains-a-slash-character – Ozan Kurt Nov 07 '19 at 06:14
  • @satish When you have passed `/` that understand new params so you must define the condition en route. – Amit Senjaliya Nov 07 '19 at 06:23

3 Answers3

3
//routes.php
Route::get('view/{slashData?}', 'ExampleController@getData')
    ->where('slashData', '(.*)');
Ozan Kurt
  • 3,731
  • 4
  • 18
  • 32
0

Your route accept only 3 params. But you pass four params.

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

You must change your val3=22-06. Don't use / as value of your param.

Eg.

URL/val1/val2/22-06 
Sok Chanty
  • 1,678
  • 2
  • 12
  • 22
0

You need to use regex expression for that situation:

Route::get('/export/{name}/{status}/{search}', 'ReportController@export')->name('export')->where(['search' => "[\w\/]+"]);
Amit Senjaliya
  • 2,867
  • 1
  • 10
  • 24