PHP code example of crow / laravel-email-template

1. Go to this page and download the library: Download crow/laravel-email-template 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/ */

    

crow / laravel-email-template example snippets


\Crow\LaravelEmailTemplate\Providers\EmailTemplateServiceProvider::class,

php artisan vendor:publish --provider="Crow\LaravelEmailTemplate\Providers\EmailTemplateServiceProvider" --tag=config

php artisan vendor:publish --provider="Crow\LaravelEmailTemplate\Providers\EmailTemplateServiceProvider" --tag=lang

php artisan email:template:publish --tag=migration

php artisan migrate



namespace Database\Seeders;

use Illuminate\Database\Seeder;

class EmailTemplateTableSeeder extends Seeder
{
    public static function data(): array
    {
        return [
            [
                'id' => 1,
                'type' => 'user_registration',
                'title' => 'title 1',
                'subject' => 'subject 1',
                'body' => 'body 1',
                'is_active' => true,
                'created_at' => '2021-01-05 15:00:00',
                'updated_at' => '2021-01-05 15:00:00',
            ],
            [
                'id' => 2,
                'type' => 'user_activate',
                'title' => 'title 2',
                'subject' => 'subject 2',
                'body' => 'body 2',
                'is_active' => true,
                'created_at' => '2021-01-05 15:00:00',
                'updated_at' => '2021-01-05 15:00:00',
            ],
        ];
    }
}

php artisan email:template:sync

$emailTemplate = \Crow\LaravelEmailTemplate\Models\EmailTemplate::query()->where('type', '=', 'user_registration')->first();
$variables = ['var1' => 'content 1']; // variable list
$wrapper = true; // (optional, default: true) use wrapper for email template
$withCopy = true; // (optional, default: true) use copy email template for render
$emailTemplate = EmailTemplateHelper::render($emailTemplate, $variables, $wrapper, $withCopy);
return $emailTemplate;



namespace App;

use Crow\LaravelEmailTemplate\EmailTemplateVariableInterface;
use Crow\LaravelEmailTemplate\Models\EmailTemplate;

class CustomEmailTemplateVariableSiteName implements EmailTemplateVariableInterface
{
    public function content(EmailTemplate $emailTemplate): ?string
    {
        return 'site name';
    }
}