1. Go to this page and download the library: Download blackpig-creatif/epitre library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
blackpig-creatif / epitre example snippets
use BlackpigCreatif\Epitre\EpitrePlugin;
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
EpitrePlugin::make(),
]);
}
namespace App\BlackpigCreatif\Epitre\Templates;
use BlackpigCreatif\Epitre\Support\EpitreTemplate;
class ContactConfirmationTemplate extends EpitreTemplate
{
protected string $key = 'contact-confirmation';
protected string $label = 'Contact Confirmation';
protected string $view = 'mail.epitre.contact-confirmation';
/** @var array<string, string> */
protected array $tokens = [
'{name}' => 'The recipient\'s name',
'{message}' => 'The message they submitted',
];
/** @return array<string, string> */
public function resolve(array $data): array
{
return [
'{name}' => $data['name'],
'{message}' => $data['message'],
];
}
}
use BlackpigCreatif\Epitre\Facades\Epitre;
use App\BlackpigCreatif\Epitre\Templates\ContactConfirmationTemplate;
public function boot(): void
{
Epitre::register(ContactConfirmationTemplate::class);
}
use BlackpigCreatif\Epitre\Concerns\HasEpitreTemplate;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Attachment;
class ContactConfirmation extends Mailable
{
use HasEpitreTemplate;
protected string $epitreKey = 'contact-confirmation';
public function __construct(
public string $name,
public string $message,
) {}
public function epitreData(): array
{
return [
'name' => $this->name,
'message' => $this->message,
];
}
public function attachments(): array
{
return [];
}
}
class OrderShipped extends Mailable
{
public function __construct(public Order $order) {}
public function envelope(): Envelope
{
return new Envelope(subject: 'Your order has shipped');
}
public function content(): Content
{
return new Content(view: 'mail.order-shipped');
}
public function attachments(): array
{
return [];
}
}
class OrderShippedTemplate extends EpitreTemplate
{
protected string $key = 'order-shipped';
protected string $label = 'Order Shipped';
protected string $view = 'mail.order-shipped'; // your existing view, unchanged
protected array $tokens = [
'{order_number}' => 'The order reference number',
'{customer_name}' => 'The recipient\'s name',
];
public function resolve(array $data): array
{
return [
'{order_number}' => $data['order_number'],
'{customer_name}' => $data['customer_name'],
];
}
}
Epitre::register(OrderShippedTemplate::class);
use BlackpigCreatif\Epitre\Concerns\HasEpitreTemplate;
class OrderShipped extends Mailable
{
use HasEpitreTemplate;
protected string $epitreKey = 'order-shipped';
public function __construct(public Order $order) {}
public function epitreData(): array
{
return [
'order' => $this->order, // still available in the Blade view
'order_number' => $this->order->reference,
'customer_name' => $this->order->customer->name,
];
}
public function attachments(): array
{
return [];
}
}
abstract class EpitreTemplate
{
protected string $key; // unique dot-notation or kebab identifier
protected string $label; // displayed in the Filament panel
protected string $view; // Blade view path for the default content
protected ?string $layout; // optional layout view for DB-stored content
protected array $tokens; // '{token}' => 'Description for editors'
abstract public function resolve(array $data): array;
}