public function sendMail()
{
switch ($this->status) {
case 'pending':
//Sends the user a mail to nitify that the
$template = 'emails.order_status_changed';
$buyer_user = User::findOrFail($this->user_id);
$email = $buyer_user->email;
$email_message = trans('email.status_changed.changed_to_pending');
$subject = trans('email.status_changed.subject1') . $this->id . ' ' . trans('email.status_changed.subject2') . ' ' . trans('store.pending');
break;
case 'closed':
//Sends the buyer a mail to notify that the Order is Closed
$template = 'emails.order_status_changed';
$seller_user = User::findOrFail($this->seller_id);
$email = $seller_user->email;
$email_message = trans('email.status_changed.changed_to_closed');
$subject = trans('email.status_changed.subject1') . $this->id . ' ' . trans('email.status_changed.subject2') . ' ' . trans('store.closed');
break;
case 'sent':
//Sends the user a mail to notify that the order is Sent
$template = 'emails.order_status_changed';
$buyer_user = User::findOrFail($this->user_id);
$email = $buyer_user->email;
$email_message = trans('email.status_changed.changed_to_sent');
$subject = trans('email.status_changed.subject1') . $this->id . ' ' . trans('email.status_changed.subject2') . ' ' . trans('store.sent');
break;
}
$data = ['order_id' => $this->id, 'email' => $email, 'email_message' => $email_message, 'new_status' => $this->status, 'subject' => $subject];
if (isset($template)) {
Mail::queue($template, $data, function ($message) use($data) {
$message->to($data['email'])->subject($data['subject']);
});
}
}