Passing "\" and "/" in a variable through the Laravel route

First of all, I apologize if this is a bad question / practice. I am very new to Laravel, so I can still handle this.

I am trying to pass a variable that contains slashes (/) and backslashes () in the Laravel 5 route, and I'm having some difficulties.

I use the following: api.dev/api/v1/service/DfDte\/uM5fy582WtmkFLJg==.

Attempt 1:

My first attempt used the following code and naturally led to 404.

Route:

Route::group(array('prefix' => 'api/v1'), function() {
    Route::resource('service', 'ServiceController');
});

Controller:

public function show($service) {
    return $service;
}

Result:

404

Attempt 2:

I searched a bit on StackOverflow and ended up using the following code, which almost works, however it seems to convert \ to /.

Route:

Route::group(array('prefix' => 'api/v1'), function() {
    Route::get('service/{slashData}', 'ServiceController@getData')
    ->where('slashData', '(.*)');
});

Controller:

public function getData($slashData = null) {
    if($slashData) {
        return $slashData;
    }
}

Result:

DfDte//uM5fy582WtmkFLJg==

As you can see, it passes the var variable, but it seems to convert \ to /.

API, , , , , (, \/).

- ?

.

+4
2

, , URL-, API-, json_encode on. json_encode , \ . JSON_UNESCAPED_SLASHES voila, .

0

. Laravel , - "/". htmlentitites html_entity_decode POST.

0

All Articles