简体   繁体   English

在Laravel中成功插入表格后,在下一页下载.PDF

[英]Download .PDF at the next page after successful form insertion in Laravel

I have a form, that user has to fill out. 我有一个表格,该用户必须填写。 After pressing submit, the user will be redirected to page called /medicines/result with a success message and download button for the .PDF. 按下提交后,用户将被重定向到/ medicines / result页面,并显示成功消息和.PDF的下载按钮。 I cannot figure out how to download the pdf on the download page. 我无法弄清楚如何在下载页面上下载pdf。 If I use the pdf method in the controller, it works fine. 如果我在控制器中使用pdf方法,则可以正常工作。

I am using this for pdf: barryvdh/laravel-dompdf 我将其用于pdf: barryvdh / laravel-dompdf

What I have: 我有的:

public function store(StoreConfirmationRequest $request) {
    $formData = $request->all();

    $prescription_confirmation = new Prescription_confirmations;
    $prescription_confirmation->physician_id = Input::get('physician_id');
    $prescription_confirmation->patient_code = Input::get('patient_code');
    $prescription_confirmation->medicine = 1;
    $prescription_confirmation->date = Input::get('physician_date');

    //finally save the data to database
    $prescription_confirmation->save();

    $pdf = App::make('dompdf.wrapper');
    $pdf->loadHTML('<h1>Test</h1>');
    $pdf->download();

    return view('medicines.result', compact('formData'))->with('message', 'Successfully inserted);
}

Here is the blade 这是刀片

 @extends ('layouts/master')

    @section('title', 'Allalaadimine')

        @section ('content')
        <div class="container medicine_confirmation_container">
          <div class="col-md-12">
            @foreach ($formData as $data)
              <li>{{$data}}</li>
            @endforeach
            <div class="flash-message">
              @if(session()->has('message'))
                  <div class="alert-message alert-message-success">
                    <h4>Saved!</h4>
                      {{ session()->get('message') }}
                  </div>
              @endif
            </div> <!-- end .flash-message -->
            <button class="btn btn-borders btn-success btn-lg btnDownloadPdf" type="submit">Lae alla pdf</button>
          </div>
        </div>
        @endsection

        @section ('footer')
        @endsection

Returning both the PDF and a view won't work. 返回PDF和视图均无效。 You have to save the PDF on your server and make it accessible to download by another route. 您必须将PDF保存在服务器上,并使其可以通过其他途径下载。

From: https://github.com/barryvdh/laravel-dompdf 来自: https : //github.com/barryvdh/laravel-dompdf

$pdf->save('/path-to/my_stored_file.pdf');

In the blade template you have to link your saved PDF. 在刀片模板中,您必须链接已保存的PDF。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM