Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

bytefury/crater

8213 stars
3 code files
View bytefury/crater on GitHub

app/Models/Payment.php

Open in GitHub
use 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 GitHub
use 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 GitHub
use 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;
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.