MailEclipse (Laravel Mail Editor)

repository·master·Indexed 24 days ago

https://github.com/qoraiche/laravel-mail-editor

A mailable editor package for Laravel that provides a web-based UI for creating, managing, and editing mailables. It features a WYSIWYG editor for HTML and Markdown, a library of 20+ email templates, and tools for previewing and sending test emails without using the command line. Includes a MailEclipse facade for programmatic template management and mailable generation.

Tokens
2.1K
Snippets
1
Records
16
Agent score
83%

What's inside MailEclipse

  1. Overview of MailEclipse features

    master

    MailEclipse (also known as Laravel Mail Editor) provides a web UI for managing mailables in Laravel. Key capabilities include:

    • No-CLI Mailable Creation: Create mailables directly through the web interface.
    • Centralized Management: Preview and edit all mailables in one place.
    • Template Library: Access over 20+ ready-to-use email templates.
    • WYSIWYG Editor: Edit email content using HTML or Markdown via a visual editor.
    • Testing Tools: Send test emails and test mailables using fake data.
  2. Install Laravel Mail Editor (MailEclipse)

    master

    Install the package via Composer and then run the installation command to publish the configuration files and public assets. The package registers itself automatically after being required.

    composer require qoraiche/laravel-mail-editor
    
    php artisan laravel-mail-editor:install
  3. Publish MailEclipse assets and configuration

    master

    To customize the package, you can use Laravel's publishing mechanism. The following tags are available for selective publishing via the CLI:

    • maileclipse.config: Publishes the config/maileclipse.php file to your application's config/ directory.
    • public: Publishes the package's public assets to public/vendor/maileclipse.
    • maileclipse.templates: Publishes the email templates to your application's resource views directory (resources/views/vendor/maileclipse/templates).
  4. Retrieve Mailable metadata and view data

    master

    The MailEclipse class can inspect existing Mailable classes to extract metadata and the data they pass to their views.

    • getMailables(): Returns a collection of all discovered Mailable classes in the configured maileclipse.mailables_dir.
    • getMailable($key, $name): Filters the mailable list by a specific key and name.
    • getMailableTemplateData($mailableName): Returns an array of data required by a specific mailable, including its view path, text view path, and the content of the template (both Blade and editor-ready markdown).
  5. Generate a new Mailable

    master

    You can programmatically trigger the creation of a new Laravel Mailable using generateMailable($request). This method wraps the Artisan make:mail command.

    Request parameters:

    • name: The name of the mailable (e.g., WelcomeUser). The class will be suffixed with Mail (e.g., WelcomeUserMail) unless the name already ends in mail.
    • markdown: (Optional) A string representing the markdown content.
    • force: (Optional) If true, it will override an existing mailable with the same name.

    Note: The mailable will be created in the directory specified by the maileclipse.mailables_dir configuration.

  6. Use the MailEclipse Facade to manage templates and mailables

    master

    The MailEclipse facade provides a static interface to the core MailEclipse API. You can use it to manage email templates, generate mailables, and preview markdown content within your Laravel application.

    Template Management

    • getTemplates(): Retrieve all templates as a Collection.
    • getTemplate($templateSlug): Retrieve a specific template by its slug.
    • createTemplate($request): Create a new template using an HTTP request.
    • updateTemplate($request): Update an existing template using an HTTP request.
    • deleteTemplate($templateSlug): Remove a template by its slug.
    • getTemplatesFile(): Get the file path where templates are stored.
    • saveTemplates(Collection $templates): Persist a collection of templates to storage.

    Mailable Operations

    • getMailables(): Retrieve all registered mailables.
    • getMailable($key, $name): Retrieve a specific mailable.
    • generateMailable($request = null): Generate a new mailable via an HTTP request.
    • buildMailable($instance, $type = 'call'): Build a mailable instance.
    • sendTest(string $name, string $recipient): Send a test email to a specific recipient.

    Previewing and Rendering

    • markdownedTemplateToView(...): Convert markdown templates to views.
    • previewMarkdownViewContent(...): Preview the content of a markdown view.
    • previewMarkdownHtml(...): Preview the HTML output of a markdown instance.
    • renderPreview(...): Render a preview of a view.
  7. Send a test email

    master

    Use sendTest($name, $recipient) to send a specific mailable to a test email address. This is useful for verifying the final output of a mailable template.

    It resolves the mailable instance, sets the to address, and clears cc and bcc recipients to ensure the test email is sent only to the intended recipient.

  8. Manage MailEclipse templates

    master

    The MailEclipse class provides static methods to manage email templates stored in a JSON file and corresponding Blade views.

    • Create a template: Use createTemplate($request) to save a new template. The $request object should contain template_name, template_description, template_type, template_view_name, template_skeleton, content (which is converted to Blade via Replacer::toBlade), and plain_text.
    • Retrieve a template: Use getTemplate($templateSlug) to get a collection containing template data, including the editor-ready content (via Replacer::toEditor), plain text version, and metadata.
    • Update a template: Use updateTemplate($request) to modify an existing template. The $request must include templateslug, title, description, and other relevant fields. The title is used to generate a new template_slug using camelCase.
    • Delete a template: Use deleteTemplate($templateSlug) to remove a template from the JSON registry and delete its associated Blade view files from the filesystem.
  9. Retrieve a specific Mailable via MailEclipseMailables::get()

    master

    Use MailEclipseMailables::get(string $name, string $key = 'name') to filter the list of available Mailables. By default, it searches by the name key (the filename without extension), but you can specify other keys like namespace or filename.

    Returns a collection containing the matching Mailable(s).