Preventing blade php function from encoding symbols

I have a route calls in my code to show an image inside a folder that has a couple subfolder based on categories. This is my route call in datatable to show the image :

<img id="pic" src="{{url('api/image',['folder/subfolder1',$data->image]}}" style="width:150;height:150"/>

i got an error cause the '/' on 'folder/subfolder1' change into '%2f', how do you prevent this from happening?? i expect the api to return link that looks something like this :

<img id="pic" src="localhost:8000/api/image/folder/subfolder1/image.jpg/>

instead i got :

<img id="pic" src="localhost:8000/api/image/folder%2fsubfolder1/image.jpg/>

the getImage controller looks something like this:

public function getImage($foldername,$filename){
$path = ['UPLOAD_PATH'].'/image';
return Image::make($path.'/'.$foldername'/'.$filename)->response();

here's the route api :

Route::get('image/{foldername}/{filename}','[email protected]')



If you expect this result below

<img id="pic" src="localhost:8000/api/image/folder/subfolder1/image.jpg" />

Then you may try this below.

<img id="pic" src="{{url('api/image/folder/subfolder1/' . $data->image }}" style="width:150;height:150"/>

Let me know if that helps.


You don't need to escape your own internal route. Use blade's non-escaped {!! !!}} instead:

<img id="pic" src="{!! url('api/image',['folder/subfolder1',$data->image] !!}" ... />

I would also perhaps make the routing a little more simple - why not just use the api/image/folder/subfolder1/'.$data->image or similar?


You may use route instead of url when sending to request url will be encoded as special char.

try using this code :

<img id="pic" src="{{route('public/image/')}$data->image}}">


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.