"I call an api that return a qrcode in xml svg format. I want to display that qrcode in blade view. I am stack with displaying the xml svg response in blade view."
I get an xml svg qrcode in controller from an API that I call, I want to display it in blade
In controller, this is how I render data to blade
return response()
->view(
'qrcode',
[
'output' => $output
],
200
)
->header('Content-Type', 'image/svg+xml');
This is how my blade look like:
<svg {{$output}}></svg>
I expect to see variable an svg xml qrcode ( $output
variable contain it)on blade view
将输出放置在svg标签之间
<svg>{{ $output }}</svg>
You need to create a Response
and attach the header to that, not the View.
$response = Response::make(View::make('qrcode', ['output' => $output]), 200);
$response->header('Content-Type', 'image/svg+xml');
return $response;
I'd also suggest just adding the header in your view, also:
<?php header('Content-Type: image/svg+xml'); ?>
{{ $output }} <!-- Try without SVG tags seems as you have XML tags in your $output anyway -->
For more info, refer to Laravel Docs
Try this it works for me:
<?php
$file_path = file_get_contents(public_path('client/assets/images') .'/'. $filename);
return response($file_path)->header('Content-Type', 'image/svg+xml');
/*The public path above is path to *.svg file*/
?>
Further we can use it on an image tag like this:
<img src="/assets/images/logo.svg" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.