
PK 
<?php
namespace App\Mail;
use App\Models\Payroll;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Storage;
class PayslipMail extends Mailable
{
use Queueable, SerializesModels;
public Payroll $payroll;
protected string $filePath;
/**
* Create a new message instance.
*/
public function __construct(Payroll $payroll, string $filePath)
{
$this->payroll = $payroll;
$this->filePath = $filePath;
}
/**
* Build the message.
*/
public function build()
{
$employee = $this->payroll->employee;
return $this->subject(
'Payslip for ' .
sprintf('%02d', $this->payroll->month) .
'/' . $this->payroll->year
)
->view('emails.payslip')
->with([
'employee' => $employee,
'payroll' => $this->payroll
])
->attach(
storage_path('app/' . $this->filePath),
[
'as' => 'Payslip_' .
$employee->emp_code . '_' .
$this->payroll->month . '_' .
$this->payroll->year . '.pdf',
'mime' => 'application/pdf'
]
);
}
}


PK 99