Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Mail Template Bundle Laravel Package

eightmarq/mail-template-bundle

View on GitHub
Deep Wiki
Context7
## Getting Started
Install the package via Composer:
```bash
composer require schvoy/mail-template-bundle

Publish the configuration file (if needed):

php artisan vendor:publish --provider="Schvoy\MailTemplateBundle\MailTemplateBundleServiceProvider"

First Use Case: Send a templated email by defining a MailTemplateEntity with either:

  • A content string (inline HTML)
  • A templatePath (path to a Blade template)

Example:

use Schvoy\MailTemplateBundle\Entity\MailTemplateEntity;

$mailTemplate = new MailTemplateEntity();
$mailTemplate->setTemplatePath(resource_path('views/emails/welcome.blade.php'));
$mailTemplate->setData(['name' => 'John']);

// Pass to your mailer (e.g., Laravel's Mail facade)
Mail::send($mailTemplate);

Implementation Patterns

Core Workflow

  1. Define Templates: Store Blade templates in resources/views/emails/ (or a custom path).
  2. Instantiate Entities: Use MailTemplateEntity for dynamic content or MailTemplateEntityInterface for custom implementations.
  3. Pass Data: Bind variables via setData() or constructor injection.
  4. Integrate with Mailers: Use Laravel’s Mail facade or a custom mailer service to dispatch.

Common Patterns

  • Reusable Templates: Cache compiled Blade templates for performance.
  • Dynamic Content: Use content for one-off emails or templatePath for reusable templates.
  • Validation: Ensure either content or templatePath is set (now enforced in v1.0.1).

Integration Tips

  • Custom Mailers: Extend Schvoy\MailTemplateBundle\Mailer\MailTemplateMailer for additional logic.
  • Doctrine ORM: If using Doctrine, leverage DoctrineBased tests as a reference for entity mapping.
  • Testing: Mock MailTemplateEntityInterface for unit tests.

Gotchas and Tips

Breaking Changes (v1.0.1)

  • Mandatory Fields: One of content or templatePath must now be set on MailTemplateEntityInterface. Older code passing empty entities will fail.

Debugging Tips

  • Template Paths: Verify paths are absolute (e.g., resource_path('views/emails/...')).
  • Blade Errors: Check for syntax errors in templates; Blade exceptions may not surface clearly.
  • Data Binding: Ensure setData() keys match template variables (e.g., {{ $name }} requires ['name' => '...']).

Extension Points

  • Custom Entities: Implement MailTemplateEntityInterface for alternative data sources (e.g., database-backed templates).
  • Mailer Decorators: Wrap the default mailer to add logging, analytics, or retry logic.
  • Template Storage: Override the default template resolver to fetch templates from a CDN or external API.

Configuration Quirks

  • Default Paths: The bundle assumes templates are in resources/views/emails/. Override via config:
    'template_paths' => [
        resource_path('views/custom-emails'),
    ],
    
  • Doctrine Integration: If using Doctrine, ensure your entity extends Schvoy\MailTemplateBundle\Entity\AbstractMailTemplateEntity.

NO_UPDATE_NEEDED would **not** apply here due to the breaking change and new enforcement in v1.0.1.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky