Send Notification in a queue with dynamically generated attachments

0

I have a notification that implements the "ShouldQueue" interface and it gets the path to a dynamically generated PDF, however I can not attach this PDF attachment, it attaches a corrupted PDF with a very small size.

Alternatively, I tried to pass the path to the PDF to be able to send as a markdown button and the user clicked to access, but I am also not able to pass the variables to the markdown view, the queue is trying to be "running" but does not advance.

Notification:

<?php
namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Queue\SerializesModels;

class SendTicketNotification extends Notification implements ShouldQueue {

    use Queueable, SerializesModels;

    /**
     * @var
     */
    protected $fileName;

    /**
     * SendTicketNotification constructor.
     * @param $fileName
     */
    public function __construct($fileName){
        $this->fileName = $fileName;
    }

    /**
     * @param $notifiable
     * @return array
     */
    public function via($notifiable){
        return ['mail'];
    }

    public function toMail($notifiable){
        return (new MailMessage())
            ->subject('Tickets - Bin@Porto 2018')
            ->markdown('mails.send_ticket_notification')
            ->with(['fileName' => $this->fileName]);
    }
}

Controller function that generates pdf and triggers notification:

public function sendByEmail(){
    $register = Registration::all();
    try{
        foreach ($register as $reg){
            $fileName = $this->createPDF($reg);
            $when = Carbon::now()->addSeconds(60);
            $reg->notify((new SendTicketNotification($fileName))->delay($when));
            // unlink(public_path($fileName));
        }
    }catch (Exception $e){
        return response()->json(['status' => $e->getMessage()]);
    }
    return response()->json(['status' => 'success', 'teste' => $fileName]);
}
    
asked by anonymous 05.09.2018 / 11:04

0 answers