Package Data | |
---|---|
Maintainer Username: | it-devgroup |
Maintainer Contact: | gavoronok30@gmail.com (Gavoronok30) |
Package Create Date: | 2021-05-11 |
Package Last Update: | 2023-08-04 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-15 03:02:31 |
Package Statistics | |
---|---|
Total Downloads: | 338 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 3 |
Total Forks: | 0 |
Total Open Issues: | 0 |
1. Open file bootstrap/app.php
Uncommented strings
$app->withFacades();
$app->withEloquent();
Added after $app->configure('app');
$app->configure('email_template_lite');
add new service provider
$app->register(\ItDevgroup\LaravelEmailTemplateLite\Providers\EmailTemplateServiceProvider::class);
2. Run commands
For creating config file
php artisan email:template:publish --tag=config
For creating migration file
php artisan email:template:publish --tag=migration
For generate table
php artisan migrate
For creating resource file
php artisan email:template:publish --tag=resource
1. Open file config/app.php and search
'providers' => [
...
]
Add to section
\ItDevgroup\LaravelEmailTemplateLite\Providers\EmailTemplateServiceProvider::class,
Example
'providers' => [
...
\ItDevgroup\LaravelEmailTemplateLite\Providers\EmailTemplateServiceProvider::class,
]
2. Run commands
For creating config file
php artisan vendor:publish --provider="ItDevgroup\LaravelEmailTemplateLite\Providers\EmailTemplateServiceProvider" --tag=config
For creating migration file
php artisan email:template:publish --tag=migration
For generate table
php artisan migrate
For creating resource file
php artisan vendor:publish --provider="ItDevgroup\LaravelEmailTemplateLite\Providers\EmailTemplateServiceProvider" --tag=resources
1. Create seeder file if not exists for email templates.
In the created seed file, you need to add a static method (for example, public static function data()
).
The method must return an array of standard to fill the database
2. Open config file config/email_template_lite.php
and add this class and method in exists parameters
'data' => [
'class' => \Database\Seeders\EmailTemplateTableSeeder::class,
'method' => 'data',
],
3. Setup section variable_parser for external or internal parser
php artisan email:template:sync
Create custom model for email template
Example:
File: app/CustomFile.php
Content:
<?php
namespace App;
class CustomFile extends \ItDevgroup\LaravelEmailTemplateLite\Model\EmailTemplate
{
}
If need change table name or need added other code:
<?php
namespace App;
class CustomFile extends \ItDevgroup\LaravelEmailTemplateLite\Model\EmailTemplate
{
protected $table = 'YOUR_TABLE_NAME';
// other code
}
Open config/email_template_lite.php and change parameter "model", example:
...
// replace
'model' => \ItDevgroup\LaravelEmailTemplateLite\Model\EmailTemplate::class,
// to
'model' => \App\CustomFile::class,
Use custom \App\CustomFile model everywhere instead of standard model \ItDevgroup\LaravelEmailTemplateLite\Model\EmailTemplate
$service = app(\ItDevgroup\LaravelEmailTemplateLite\EmailTemplateServiceInterface::class);
or injected
// use
use ItDevgroup\LaravelEmailTemplateLite\EmailTemplateServiceInterface;
// constructor
public function __construct(
EmailTemplateServiceInterface $emailTemplateService
)
further we will use the variable $service
All email templates
$eloquentCollection = $service->getList();
Email templates with filter. All filter parameters not required
$filter = (new \ItDevgroup\LaravelEmailTemplateLite\Model\EmailTemplateFilter())
->setIsPublic(true);
// or
$filter = (new \ItDevgroup\LaravelEmailTemplateLite\Model\EmailTemplateFilter())
->setType('type_name_by_like')
->setTitle('title_by_like')
->setIsActive(true);
$eloquentCollection = $service->getList($filter);
Email templates with pagination
$lengthAwarePaginator = $service->getList(null, $page, $perPage);
$lengthAwarePaginator = $service->getList(null, 1, 10);
Email templates with sorting
$eloquentCollection = $service->getList(null, null, null, $fieldName, $ascOrDesc);
$eloquentCollection = $service->getList(null, null, null, 'title', 'ASC');
$emailTemplate = $service->getById(1);
$emailTemplate = $service->getByType('emailTemplate_type');
$emailTemplate = \ItDevgroup\LaravelEmailTemplateLite\Model\EmailTemplate::register(
'type',
'Title',
'Subject',
'Body'
);
$emailTemplate->is_active = true;
$service->createModel($emailTemplate);
$emailTemplate = $service->getById(1);
$emailTemplate->title = 'Title';
$emailTemplate->subject = 'Subject';
$emailTemplate->body = 'Body';
$emailTemplate->is_active = true;
$service->updateModel($emailTemplate);
$emailTemplate = $service->getById(1);
$service->deleteModel($emailTemplate);
$emailTemplate = $service->getById(1);
// or
$emailTemplate = $service->getByType('type');
$service->render($emailTemplate, ['test_1' => '111', 'test_2' => 222]);
return $emailTemplate;
$service->preview($emailTemplate);
//
return $emailTemplate;
$emailTemplate = $service->getById(1);
// or
$emailTemplate = $service->getByType('type');
$emailTemplate->variables; // Collection
$emailTemplate->variables[0]->key;
$emailTemplate->variables[0]->description;
return $service->emailWrapper();
$service->setEmailWrapper('email-template.wrapper');
Add to seeder file
Run sync command
php artisan email:template:sync
Add email template variables to config file config/email_template_lite.php in section variables
Add text for variables in to lexicon file resources/lang/LANG_KEY/email_template_variables.php
'variables' => [
'common' => [
'site_name' => \App\CustomEmailTemplateVariableSiteName::class,
],
...
Create class \App\CustomEmailTemplateVariableSiteName
The class must be an implementation of the interface ItDevgroup\LaravelEmailTemplateLite\EmailTemplateVariableInterface
The class must contain a public method toString(): ?string
Full example file
<?php
namespace App;
use ItDevgroup\LaravelEmailTemplateLite\EmailTemplateVariableInterface;
class CustomEmailTemplateVariableSiteName implements EmailTemplateVariableInterface
{
public function toString(): ?string
{
return 'site name';
}
}
For test need phpunit
vendor/bin/phpunit vendor/it-devgroup/laravel-email-template-lite