First off, apologies if this is a bad question/practice. I'm very new to Laravel, so I'm still getting to grips with it.
I'm attempting to pass a variable that contains forward slashes (/) and backwards slashes () in a Laravel 5 route and I'm having some difficulties.
I'm using the following: api.dev/api/v1/service/DfDte\/uM5fy582WtmkFLJg==.
Attempt 1:
My first attempt used the following code and naturally resulted in a 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 did a bit of searching on StackOverflow and ended up using the following code, which almost works, however, it appears to be converting \ 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's passing the var but appears to be converting the \ to /.
I'm attempting to create an API and unfortunately the variable I'm passing is out of my control (e.g. I can't simply not use \ or /).
Does anyone have any advice or could point me in the right direction?
Thanks.
api.dev/api/v1/service/DfDte\/uM5fy582WtmkFLJg==is meant to be a request URL, then note that it is obviously invalid. A back slash is not a valid character in a URL, you'd have to "percent encode" it. Or, if in reality you want to escape the following forward slash, then likewise: don't use a backslash, but URL encode the slash instead. Just as the formal definition for URLs request.DfDte%5C%2FuM5fy582WtmkFLJg%3D%3Dbut that just leads to another 404 using the code provided in "Attempt 2".\/sounds extremely unlikely to me. Are you really sure this is not just a notation meant to escape the contained forward slash?