A Laravel package that allow your customers to edit email templates (html and markdown).
The package has been developed and tested to work with the following minimum requirements:
- PHP 8.0
- Laravel 8.0
You can install the package via Composer:
composer require skywebdev/laravel-db-view
This package contains migration that add table: blade_templates
.
To run these migration, simply run the following command:
php artisan migrate
After migration you should run following seeder that will import email templates to database.
php artisan db:seed --class="SkyWebDev\Database\Seeders\AddBladeTemplatesSeeder"
You should run this seeder whenever new email template is added.
After installation your Mailable class will read body and subject from table blade_templates
. You can
allow
customers to change
them on front using rich text and markdown editors.
Package contains CRUD routes for maintaining blade_templates
tables. Nothing special, I would just emphasize that
delete is actually revert to original. Delete will revert content and subject to be same as defined in blade file.
Update and delete will clear view cache.
Verb | URI | Action | Name |
---|---|---|---|
GET | /blade-templates | index | blade-templates.index |
POST | /blade-templates | create | blade-templates.create |
GET | /blade-templates/{bladeTemplate} | show | blade-templates.show |
PUT | /blade-templates/{bladeTemplate} | update | blade-templates.update |
DELETE | /blade-templates/{bladeTemplate} | destroy | blade-templates.destroy |
Create markdown mail
php artisan make:mail TestMail --markdown=test_mail
This command will create App\Mail\TestMail
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class TestMail extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Get the message envelope.
*
* @return \Illuminate\Mail\Mailables\Envelope
*/
public function envelope()
{
return new Envelope(
subject: 'Test Mail',
);
}
/**
* Get the message content definition.
*
* @return \Illuminate\Mail\Mailables\Content
*/
public function content()
{
return new Content(
markdown: 'test_mail',
);
}
/**
* Get the attachments for the message.
*
* @return array
*/
public function attachments()
{
return [];
}
}
and view file resource/views/test_mail.blade.php
in markdown format
<x-mail::message>
# Introduction
The body of your message.
<x-mail::button :url="''">
Button Text
</x-mail::button>
Thanks,<br>
{{ config('app.name') }}
</x-mail::message>
In routes.web.php
add route for displaying mail.
<?php
use Illuminate\Support\Facades\Route;
Route::get('/mail', function () {
return (new \App\Mail\TestMail());
});
Call <app_url>/mail
in browser and you will see something like this
Run seeder for adding blade templates to db
php artisan db:seed --class="SkyWebDev\Database\Seeders\AddBladeTemplatesSeeder"
This seeder will add newly added template to blade_templates
table.
Next, edit body column of newly added template in blade_templates
table. For example append DB in button label.
<x-mail::button :url="''">
Button Text DB
</x-mail::button>
Clear view cache
php artisan view:clear
Refresh <app_url>/mail
in browser and you will see something like this
Template is rendered from db.