ldc-boutique-cnc/app/Notifications/ContactForm.php
2023-02-13 14:57:01 +01:00

85 lines
2.4 KiB
PHP

<?php
namespace App\Notifications;
use App\Models\Contact;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\MailMessage;
class ContactForm extends Notification
{
/**
* Order
*
* @var \App\Models\Contact
*/
private $notifiable;
/**
* Create a new controller instance.
*
* @param \App\Models\Contact $model
* @return void
*/
public function __construct(Contact $model)
{
$this->notifiable = $model;
}
/**
* Get the notification's delivery channels.
*
* @return array
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
*/
public function via()
{
return ['mail'];
}
/**
* Build the mail representation of the notification.
*
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail()
{
/** @var string $subject */
$subject = $this->notifiable->subject;
/** @var string $firstname */
$firstname = $this->notifiable->firstname;
/** @var string $lastname */
$lastname = $this->notifiable->lastname;
/** @var string $email */
$email = $this->notifiable->email;
/** @var string $email */
$email = $this->notifiable->email;
/** @var string $orderNumber */
$orderNumber = $this->notifiable->order_number;
/** @var string $message */
$message = $this->notifiable->message;
/** @var string $file */
$file = $this->notifiable->file;
$notification = (new MailMessage())
->subject(trans("Contact - :siteName - " . $subject, [
'siteName' => config('theme.site_name')
]))
->line(trans("Voici un message envoyé depuis :siteName :", [
'siteName' => config('theme.site_name')
]))
->line(trans("Expéditeur : :firstname :lastname", [
'firstname' => $firstname,
'lastname' => $lastname
]))
->line(trans("Email : :email", ['email' => $email]));
($orderNumber) ? $notification->line(trans("Référence commande : :num", [
'num' => $orderNumber ?? 'non saisie'
])) : $notification;
$notification->line($message);
return ($file) ? $notification->attach($file) : $notification;
}
}