mail-sender
Mail block that sends email by template for Laravel 5.3 / Laraflock Dashboard, (*1)
Install
- Require in composer:
composer require preshetin/mail-sender:dev-master
- Then register in
config/app.php
providers' => [
...
Preshetin\MailSender\MailSenderServiceProvider::class,
];
- Run migrations to create
mail_logs
& mail_templates
tables:
php artisan migrate
- Add
MailableEntity
interface & MailSenderTrait
trait in any Eloquent model:
use Preshetin\MailSender\MailSenderTrait;
use Preshetin\MailSender\Model\MailableEntity;
class Order extends Model implements MailableEntity
{
use MailSenderTrait;
// ...
}
-
MailableEntity
interface will require you to add a couple of methods:
This is where email sends TO:, (*2)
public function getEmail()
{
return $this->user->email;
}
And getMailTemplateReplacements
which gets values for mail template variables:, (*3)
public function getMailTemplateReplacements()
{
return [
'[ORDER_ID]' => $this->id,
'[NAME]' => $this->user->name,
...
];
}
That's it! Now you may insert Blade templates and get mail send functionality!, (*4)
Usage
Add in blade templates:, (*5)
@include('mail-sender::partials.mail', ['mailable_entity' => $order])
Also, you may add to your sidebar:, (*6)
@include('mail-sender::partials.sidebar')
Configuration
You may php artisan vendor:publish
config mail-sender.php
. There you may ajust a view for emails:, (*7)
'mail_view' => 'emails.your_custom_view',