2017-12-19 8 views
2

現在、私は現在、laravel-snappyを使用してページからPDFを生成しています。これは主に、生成されたいくつかのページにあるJavaScriptスクリプトで本当にうまいです。Laravelから生成されたPDFをMailableに添付する

mappに添付ファイルを添付することができます。これは、通知がいくつかの問題を解決するまで他のユーザーの提案で使用しています。

しかし、私は、生成されたPDFをmailableに添付することができるかどうかは固まっています。その後、コントローラで、ここに送られ

Route::get('/shipments/download/{shipment}','[email protected]'); 

は:

public function downloadPDF(Shipment $shipment){ 
      $shipment_details = $shipment->shipment_details; 

      $pdf = PDF::loadView('shipments.pdf', compact('shipment','shipment_details')) 
        ->setOption('images', true) 
        ->setOption('enable-javascript', true) 
        ->setOption('javascript-delay', 100); 
      return $pdf->download('shipment'.$shipment->url_string.'.pdf'); 
     } 

マイmailableは、このような次のように定義されます

は現時点では、私はルートで生成するPDFを送る

<?php 

namespace App\Mail; 

use Illuminate\Bus\Queueable; 
use Illuminate\Mail\Mailable; 
use Illuminate\Queue\SerializesModels; 
use Illuminate\Contracts\Queue\ShouldQueue; 

use App\Shipment; 

class newFreightBill extends Mailable 
{ 
    use Queueable, SerializesModels; 

    /** 
    * Create a new message instance. 
    * 
    * @return void 
    */ 
    public $shipment; 

    public function __construct(Shipment $shipment) 
    { 
     $this->shipment = $shipment; 
     $this->attachmentURL = $shipment->url_string; 
     $this->proNumber = $shipment->pro_number; 
    } 

    /** 
    * Build the message. 
    * 
    * @return $this 
    */ 
    public function build() 
    { 
     return $this->from('[email protected]') 
        ->subject('New Freight Bill Created - '. $this->proNumber) 
        ->view('emails.shipments.created'); 
    } 
} 

これで、生成されたPDFを添付できますか?

答えて

0

添付ファイルを使用してメールでファイルを送信できます。例: -

public function build() 
    { 
     return $this->from('[email protected]') 
        ->subject('New Freight Bill Created - '. $this->proNumber) 
        ->view('emails.shipments.created') 
        ->attach($your_pdf_file_path_goes_here); 
    } 

これは私が試している間に私のために働いた。それもあなたのために働くことを願っています。ここで私はPDF生成に

手順laravelパッケージ "vsmoraes/laravel-PDF" を使用しています

0

1)は、動的データ

2とのビューをレンダリング)PDF

に、このビューをロード

3)pdfデータをメールに添付

$html = view('pdf',compact('result','score'))->render(); 
$pdf = PDF::Load($html); 

Mail::send('mail.analysis',['user'=>$data],function($message) use($pdf,$user){ 
    $message->to($user->email)->subject("Page Speed Aanlysis Generated"); 
    $message->attachData($pdf->output(),'pdf_name.pdf'); 
}); 
関連する問題