-
app/Abstracts/Notification.php
Open in GitHubuse Illuminate\Notifications\Notification as BaseNotification; abstract class Notification extends BaseNotification { public function initMessage() { app('url')->defaults(['company_id' => company_id()]); $message = (new MailMessage) ->from(config('mail.from.address'), config('mail.from.name')) ->subject($this->getSubject()) ->view('partials.email.body', ['body' => $this->getBody()]); return $message; } }
-
app/Notifications/Sale/Invoice.php
Open in GitHubuse App\Abstracts\Notification; use App\Models\Common\EmailTemplate; class Invoice extends Notification { public $invoice; public $template; public $attach_pdf; public function __construct($invoice = null, $template_alias = null, $attach_pdf = false) { parent::__construct(); $this->invoice = $invoice; $this->template = EmailTemplate::alias($template_alias)->first(); $this->attach_pdf = $attach_pdf; } public function toMail($notifiable) { $message = $this->initMessage(); // Attach the PDF file if ($this->attach_pdf) { $message->attach($this->storeDocumentPdfAndGetPath($this->invoice), [ 'mime' => 'application/pdf', ]); } return $message; } }
-
app/Http/Controllers/Sales/Invoices.php
Open in GitHubuse App\Notifications\Sale\Invoice as Notification; use App\Abstracts\Http\Controller; class Invoices extends Controller { // public function emailInvoice(Document $invoice) { if (empty($invoice->contact_email)) { return redirect()->back(); } // Notify the customer $invoice->contact->notify(new Notification($invoice, 'invoice_new_customer', true)); event(new \App\Events\Document\DocumentSent($invoice)); flash(trans('documents.messages.email_sent', ['type' => trans_choice('general.invoices', 1)]))->success(); return redirect()->back(); } }