【问题标题】:Laravel barryvdh/laravel-dompdfLaravel barryvdh/laravel-dompdf
【发布时间】:2016-12-05 13:28:21
【问题描述】:

我正在使用 Laravel 5.2 并打包“barryvdh/laravel-dompdf”。我正在像这样流式传输/查看视图文件:

$manu = Mmanufacturer::select('manName')->find($manuid);
        $prds = compact('prds','images','temp_header','temp_footer');
        return PDF::loadView('cp.reports.letters-pdf', $prds)->stream();

这会打开适当的视图并且工作正常...参见图片: http://prntscr.com/dflj4d

在 url 的末尾,你看到 '43' 默认是 id..我想在最后显示的是制造商/产品或其他名称而不是它的 id..我们能做到这一点吗?

【问题讨论】:

    标签: laravel-5.2 dompdf


    【解决方案1】:

    您可以为查看pdf设置自定义路由,通过post方法发送参数。喜欢:

    Route::post('/manufacturer/product', 'ReportController@viewPdf');
    

    如果你使用按钮,那么使用这种方式:

    <a href="#!" onclick="event.preventDefault();document.getElementById('viewPdf').submit();">View Pdf</a>
    

    查看 PDF 表单

    <form id="viewPdf" action="{{ url('/manufacturer/product') }}" method="POST" style="display: none;">
           <input type="hidden" name="product_id" value="43">
        {{ csrf_field() }}  
    </form>
    

    在控制器中:

     $manuid= $request->product_id;
     $manu = Mmanufacturer::select('manName')->find($manuid);
     $prds = compact('prds','images','temp_header','temp_footer');
     return PDF::loadView('cp.reports.letters-pdf', $prds)->stream();
    

    希望这个技巧会有所帮助。谢谢你:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-12
      • 1970-01-01
      • 2023-04-09
      • 2019-09-08
      • 1970-01-01
      • 1970-01-01
      • 2023-03-08
      • 2019-12-20
      相关资源
      最近更新 更多