-
app/Models/Payment.php
Open in GitHubuse Illuminate\Database\Eloquent\Model; use Crater\Mail\SendPaymentMail; class Payment extends Model { // public function send($data) { $data['payment'] = $this->toArray(); $data['user'] = $this->user->toArray(); $data['company'] = Company::find($this->company_id); $data['body'] = $this->getEmailBody($data['body']); $data['attach']['data'] = ($this->getEmailAttachmentSetting()) ? $this->getPDFData() : null; \Mail::to($data['to'])->send(new SendPaymentMail($data)); return [ 'success' => true, ]; } // }
-
app/Http/Controllers/V1/Payment/SendPaymentController.php
Open in GitHubuse Crater\Http\Controllers\Controller; use Crater\Http\Requests\SendPaymentRequest; use Crater\Models\Payment; class SendPaymentController extends Controller { public function __invoke(SendPaymentRequest $request, Payment $payment) { $response = $payment->send($request->all()); return response()->json($response); } }
-
app/Mail/SendPaymentMail.php
Open in GitHubuse Crater\Models\EmailLog; use Crater\Models\Payment; use Illuminate\Mail\Mailable; class SendPaymentMail extends Mailable { // public function build() { EmailLog::create([ 'from' => $this->data['from'], 'to' => $this->data['to'], 'subject' => $this->data['subject'], 'body' => $this->data['body'], 'mailable_type' => Payment::class, 'mailable_id' => $this->data['payment']['id'], ]); $mailContent = $this->from($this->data['from'], config('mail.from.name')) ->subject($this->data['subject']) ->markdown('emails.send.payment', ['data', $this->data]); if ($this->data['attach']['data']) { $mailContent->attachData( $this->data['attach']['data']->output(), $this->data['payment']['payment_number'].'.pdf' ); } return $mailContent; } }