【发布时间】:2020-01-21 18:35:59
【问题描述】:
我正在通过以下方式生成 PDF:laravel-dompdf
我似乎无法让动态 URL 正常工作。
示例:
在我的刀片文件中,我有这样的内联样式设置,我需要背景图像是完整路径:
<style>
.cardbg{
background: url('https://examplesite.com/images/pic.jpg')
}
/* I've tried the following variations with no luck.
I don't understand why this is not working. */
background: url('{{asset('/images/pic.jpg')}}');
background: url('{{public_path('/images/pic.jpg')}}');
background: url('{{storage_path('/images/pic.jpg')}}');
background: url('{{config('app.url').'/images/pic.jpg'}}');
</style>
还在我的控制器中添加了指向变量的直接路径,如下所示:
public function examplePdf($id){
$pdfbg = config('app.url').'/images/pic.jpg';
$pdf = PDF::loadView('admin.dir.example-pdf', compact('pdfbg'))->setPaper('letter', 'landscape');
return $pdf->stream('example.pdf');
然后在刀片中这样调用<style>:
.cardbg{
background: url('{{$pdfbg}}');
}
仍然没有...这没有意义,因为当我执行dd($pdfbg); 时,我得到了图像的正确路径。 "https://examplesite.com/images/pic.jpg"
通过这样做,我确实获得了在 <style> 标签之外正确渲染的完整路径:
<img src="{{public_path("/storage/images/folder/$var->example/profile-img/$var->img_name")}}">
任何帮助将不胜感激。
【问题讨论】: