added mailer and boot method create on project mailing
This commit is contained in:
parent
3a18e3b8a7
commit
540e9113dd
|
|
@ -35,6 +35,5 @@ public function download()
|
||||||
public function createMailing() {
|
public function createMailing() {
|
||||||
$this->mailingForm->save();
|
$this->mailingForm->save();
|
||||||
$this->reset('createMailingModal');
|
$this->reset('createMailingModal');
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,23 +2,30 @@
|
||||||
|
|
||||||
namespace App\Mail;
|
namespace App\Mail;
|
||||||
|
|
||||||
|
use App\Models\ProjectMailing;
|
||||||
|
use App\Models\ProjectMailingAttachment;
|
||||||
|
use App\Models\ProjectMosaic;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Mail\Mailable;
|
use Illuminate\Mail\Mailable;
|
||||||
|
use Illuminate\Mail\Mailables\Attachment;
|
||||||
use Illuminate\Mail\Mailables\Content;
|
use Illuminate\Mail\Mailables\Content;
|
||||||
use Illuminate\Mail\Mailables\Envelope;
|
use Illuminate\Mail\Mailables\Envelope;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
class ReportMailer extends Mailable
|
class ReportMailer extends Mailable
|
||||||
{
|
{
|
||||||
use Queueable, SerializesModels;
|
use Queueable, SerializesModels;
|
||||||
|
|
||||||
|
public ProjectMailing $mailing;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new message instance.
|
* Create a new message instance.
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct(ProjectMailing $mailing)
|
||||||
{
|
{
|
||||||
//
|
$this->mailing = $mailing;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -27,7 +34,7 @@ public function __construct()
|
||||||
public function envelope(): Envelope
|
public function envelope(): Envelope
|
||||||
{
|
{
|
||||||
return new Envelope(
|
return new Envelope(
|
||||||
subject: 'Report Mailer',
|
subject: $this->mailing->subject,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -37,9 +44,15 @@ public function envelope(): Envelope
|
||||||
public function content(): Content
|
public function content(): Content
|
||||||
{
|
{
|
||||||
return new Content(
|
return new Content(
|
||||||
view: 'view.name',
|
htmlString: $this->mailing->message,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
public function build(): self
|
||||||
|
{
|
||||||
|
$this->to($this->mailing->recipients()->pluck('email')->toArray());
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the attachments for the message.
|
* Get the attachments for the message.
|
||||||
|
|
@ -48,6 +61,14 @@ public function content(): Content
|
||||||
*/
|
*/
|
||||||
public function attachments(): array
|
public function attachments(): array
|
||||||
{
|
{
|
||||||
return [];
|
return $this->mailing->attachments()->get()->map(function (ProjectMailingAttachment $attachment) {
|
||||||
|
$projectPath = $attachment->mailing()->project()->first()->path;
|
||||||
|
|
||||||
|
return Attachment::fromStorage(
|
||||||
|
path: $projectPath.$attachment->path
|
||||||
|
)
|
||||||
|
->as($attachment->name)
|
||||||
|
->withMime('application/pdf');
|
||||||
|
})->toArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,13 @@ class ProjectMailing extends Model
|
||||||
'message',
|
'message',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
protected static function booted()
|
||||||
|
{
|
||||||
|
static::created(function ($projectMailing) {
|
||||||
|
Mail::send(new \App\Mail\ReportMailer($projectMailing));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public function addAttachment($name, UploadedFile $file)
|
public function addAttachment($name, UploadedFile $file)
|
||||||
{
|
{
|
||||||
$prefix = Str::random(10);
|
$prefix = Str::random(10);
|
||||||
|
|
|
||||||
|
|
@ -13,4 +13,9 @@ class ProjectMailingAttachment extends Model
|
||||||
'name',
|
'name',
|
||||||
'path',
|
'path',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public function mailing()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(ProjectMailing::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@
|
||||||
</x-menu.button>
|
</x-menu.button>
|
||||||
|
|
||||||
<x-menu.items>
|
<x-menu.items>
|
||||||
|
|
||||||
<x-menu.close>
|
<x-menu.close>
|
||||||
<x-menu.item wire:click="download">
|
<x-menu.item wire:click="download">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue