simplify variables names for templates, refactor to be multi-model
This commit is contained in:
@@ -56,9 +56,9 @@ class MailTemplateController extends Controller
|
||||
return view('Admin.Core.Mail.MailTemplate.partials.vars', $data);
|
||||
}
|
||||
|
||||
public function preview($template_id, $user_id)
|
||||
public function preview($template_id, $model_id)
|
||||
{
|
||||
return MailTemplates::preview($template_id, $user_id);
|
||||
return MailTemplates::preview($template_id, $model_id);
|
||||
}
|
||||
|
||||
public function modalPreview($template_id)
|
||||
|
||||
@@ -3,15 +3,14 @@
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\Core\Mail\MailTemplate;
|
||||
use App\Repositories\Shop\Traits\MailCustomers;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailables\Address;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Spatie\MailTemplates\TemplateMailable;
|
||||
|
||||
class Acheminement extends TemplateMailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
use MailCustomers, Queueable, SerializesModels;
|
||||
|
||||
protected static $templateModelClass = MailTemplate::class;
|
||||
|
||||
@@ -29,12 +28,4 @@ class Acheminement extends TemplateMailable
|
||||
$this->male = $user->gender == 1;
|
||||
$this->subject = $subject;
|
||||
}
|
||||
|
||||
public function envelope()
|
||||
{
|
||||
return new Envelope(
|
||||
from: new Address('boutique@jardinenvie.com', 'Boutique Jardin\'Envie'),
|
||||
subject: $this->subject,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,38 +3,33 @@
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\Core\Mail\MailTemplate;
|
||||
use App\Repositories\Shop\Traits\MailCustomers;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailables\Address;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Spatie\MailTemplates\TemplateMailable;
|
||||
|
||||
class Bienvenue extends TemplateMailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
use MailCustomers, Queueable, SerializesModels;
|
||||
|
||||
protected static $templateModelClass = MailTemplate::class;
|
||||
|
||||
public $user;
|
||||
public $email;
|
||||
|
||||
public $male;
|
||||
public $nom;
|
||||
|
||||
public $prenom;
|
||||
|
||||
public $societe;
|
||||
|
||||
public $subject;
|
||||
|
||||
public $url;
|
||||
|
||||
public function __construct($user, $subject = '')
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->male = $user->gender == 1;
|
||||
$this->prenom = $user->first_name;
|
||||
$this->nom = $user->last_name;
|
||||
$this->societe = $user->society;
|
||||
$this->email = $user->email;
|
||||
$this->subject = $subject;
|
||||
}
|
||||
|
||||
public function envelope()
|
||||
{
|
||||
return new Envelope(
|
||||
from: new Address('boutique@jardinenvie.com', 'Jardin\'en\'Vie'),
|
||||
subject: $this->subject,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,15 +3,14 @@
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\Core\Mail\MailTemplate;
|
||||
use App\Repositories\Shop\Traits\MailCustomers;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailables\Address;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Spatie\MailTemplates\TemplateMailable;
|
||||
|
||||
class ConfirmationCommande extends TemplateMailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
use MailCustomers, Queueable, SerializesModels;
|
||||
|
||||
protected static $templateModelClass = MailTemplate::class;
|
||||
|
||||
@@ -21,20 +20,10 @@ class ConfirmationCommande extends TemplateMailable
|
||||
|
||||
public $subject;
|
||||
|
||||
public $url;
|
||||
|
||||
public function __construct($user, $subject = '')
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->male = $user->gender == 1;
|
||||
$this->subject = $subject;
|
||||
}
|
||||
|
||||
public function envelope()
|
||||
{
|
||||
return new Envelope(
|
||||
from: new Address('boutique@jardinenvie.com', 'Boutique Jardin\'Envie'),
|
||||
subject: $this->subject,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,38 +3,33 @@
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\Core\Mail\MailTemplate;
|
||||
use App\Repositories\Shop\Traits\MailCustomers;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailables\Address;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Spatie\MailTemplates\TemplateMailable;
|
||||
|
||||
class Preparation extends TemplateMailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
use MailCustomers, Queueable, SerializesModels;
|
||||
|
||||
protected static $templateModelClass = MailTemplate::class;
|
||||
|
||||
public $user;
|
||||
public $email;
|
||||
|
||||
public $male;
|
||||
public $nom;
|
||||
|
||||
public $prenom;
|
||||
|
||||
public $societe;
|
||||
|
||||
public $subject;
|
||||
|
||||
public $url;
|
||||
|
||||
public function __construct($user, $subject = '')
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->male = $user->gender == 1;
|
||||
$this->prenom = $user->first_name;
|
||||
$this->nom = $user->last_name;
|
||||
$this->societe = $user->society;
|
||||
$this->email = $user->email;
|
||||
$this->subject = $subject;
|
||||
}
|
||||
|
||||
public function envelope()
|
||||
{
|
||||
return new Envelope(
|
||||
from: new Address('boutique@jardinenvie.com', 'Boutique Jardin\'Envie'),
|
||||
subject: $this->subject,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,16 +38,17 @@ class MailTemplates
|
||||
|
||||
return [
|
||||
'id' => $id,
|
||||
'users' => $mailable::getUsers(),
|
||||
'list' => $mailable::getContext(),
|
||||
];
|
||||
}
|
||||
|
||||
public static function preview($id, $user_id)
|
||||
public static function preview($id, $model_id)
|
||||
{
|
||||
$template = self::get($id);
|
||||
$mailable = $template->mailable;
|
||||
$data = $mailable::getDataByUser($user_id);
|
||||
$html_template = $template->toArray()['html_template_translations'][$data['lang']] ?? false;
|
||||
$data = $mailable::getData($model_id);
|
||||
|
||||
$html_template = $template->toArray()['html_template_translations'][$data['lang'] ?? 'fr'] ?? false;
|
||||
if ($html_template) {
|
||||
$m = new Mustache_Engine();
|
||||
|
||||
|
||||
@@ -18,6 +18,11 @@ class Customers
|
||||
return Customer::count();
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Customer::pluck('last_name', 'id');
|
||||
}
|
||||
|
||||
public static function editProfile($id = false)
|
||||
{
|
||||
$id = $id ? $id : self::getId();
|
||||
|
||||
41
app/Repositories/Shop/Traits/MailCustomers.php
Normal file
41
app/Repositories/Shop/Traits/MailCustomers.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop\Traits;
|
||||
|
||||
use App\Repositories\Shop\Customers;
|
||||
use App\Repositories\Core\DateTime;
|
||||
use Illuminate\Mail\Mailables\Address;
|
||||
use Illuminate\Mail\Mailables\Envelope;
|
||||
|
||||
trait MailCustomers
|
||||
{
|
||||
public static function getContext()
|
||||
{
|
||||
return Customers::getOptions();
|
||||
}
|
||||
|
||||
public static function getData($id)
|
||||
{
|
||||
$user = self::getUser($id);
|
||||
|
||||
return $user ? [
|
||||
'prenom' => $user->first_name,
|
||||
'nom' => $user->last_name,
|
||||
'societe' => $user->society,
|
||||
'email' => $user->email,
|
||||
] : false;
|
||||
}
|
||||
|
||||
public static function getUser($id)
|
||||
{
|
||||
return Customers::get($id);
|
||||
}
|
||||
|
||||
public function envelope()
|
||||
{
|
||||
return new Envelope(
|
||||
from: new Address('boutique@jardinenvie.com', 'Jardin\'en\'Vie'),
|
||||
subject: $this->subject,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user