定制 atomjoy/lara 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

atomjoy/lara

Composer 安装命令:

composer require atomjoy/lara

包简介

Lara is an HTML email template for Laravel notifications.

README 文档

README

Lara is a custom theme for HTML email notifications in Laravel 13.

Install

composer create-project laravel/laravel:^13 test
cd test
composer require atomjoy/lara

After Install

# Publish lara email images to public/vendor/lara and update logo and banner
php artisan vendor:publish --tag=lara-images --force

Show Lara Email Theme

Lara email notification examples in LaraNotificanion class.

<?php

use App\Models\User;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Notification;
use Lara\Notifications\LaraNotificanion;

// Set smtp settings in .env file
Route::get('/lara', function () {

    // Make user
    $user = User::factory()->make([
        'email' => 'your-email@example.com'
    ]);

    // Send notification email
    Notification::sendNow($user, new LaraNotificanion());

    // Show in browser
    return (new LaraNotificanion())->toMail($user);
});

Run

npm install
npm run build
php artisan serve
php artisan serve --host=localhost --port=8000

How To Use with Notifications

In the terminal, type php artisan make:notification EmailNotification to create notification class, then update methods.

<?php

public function via(object $notifiable): array
{
    return ['mail'];
}

public function toMail(object $notifiable): MailMessage
{
    // Page url
    $page = app()->request->getSchemeAndHttpHost();
    // Demo image url
    $host = 'https://raw.githubusercontent.com/atomjoy/lara/refs/heads/main/public';

    // Track views image (return image content from url)
    // $trackingUrl = '/track/email/views/' . $this->newsletter->id . '/' . $this->notifiable->id;
    // config([
    //     'mail.email.tracking.image.url' => $trackingUrl
    // ]);

    // Lara config email template links and images always with https://
    config([
        // Show
            'mail.email.browser' => $page . "/email/123",

            // Change
            // 'mail.email.link' => 'https://example.com',
            // 'mail.email.logo' =>  $host . "/email/logo.webp",
            // 'mail.email.banner' => "https://images.unsplash.com/photo-1556125574-d7f27ec36a06?q=80&w=1170&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",

            // Hide
            // 'mail.email.logo' => null,
            // 'mail.email.banner' => null,
            // 'mail.email.browser' => null,

            // Email title
            // 'mail.email.products.title' => 'Fresh promotions',
            // 'mail.email.events.title' => 'Upcoming live events',
            // 'mail.email.info.title' => 'Looking for more?',

            // Footer url
            // 'mail.email.footer.logo' => 'https://example.com/footer-logo.webp',
            // 'mail.email.footer.unsubscribe' => 'https://example.com/unsubscribe',
            // 'mail.email.footer.policy' => 'https://example.com/policy',
            // 'mail.email.footer.settings' => 'https://example.com/settings',

            // Show footer social icons
            'mail.email.social.instagram' => 'https://instagram.com/',
            'mail.email.social.facebook' => 'https://facebook.com/',
            'mail.email.social.youtube' => 'https://youtube.com/',
            'mail.email.social.tiktok' => 'https://tiktok.com/',
            'mail.email.social.x' => 'https://x.com/',
    ]);

    // ...

    // Defaut theme events, products
    return (new MailMessage())
        // ->error()->success()
        // ->salutation('Best regards from our team')
        ->subject('Events notification')
        ->greeting('Web Interaction in the Age of AI')
        ->line('The introduction to the notification. Bold <strong>html tekst</strong> goes here. Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quos eum ex, atque, porro debitis cumque praesentium, dolore illo ullam nemo doloremque at nobis?')
        ->action('Confirm Email Address', $page . '/confirm/email') // Dont use url() function
        ->line('Thank you for using our application, <a href="https://example.com" target="_blank">very nice!</a>')
        // Set default or mini theme and markdown
        ->theme('lara::theme.default')
        ->markdown('lara::email.default', [
            // Comment to hide
            'date' => 'March 28, 4PM CET',
            'code' => '888777',
            'info' => 'Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quos eum ex, atque, porro debitis cumque praesentium, dolore illo ullam nemo doloremque at nobis? Nesciunt neque molestias expedita eius voluptate saepe.',
            'products' => $products,
            'events' => $events,
            'news' => $news,
        ]);
}

How To Use with Mailable

<?php

namespace App\Mail;

use App\Models\Newsletter;
use App\Models\Social;
use App\Models\Subscriber;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Address;
use Illuminate\Mail\Mailables\Attachment;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Queue\SerializesModels;

class NewsletterMail extends Mailable implements ShouldQueue
{
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     */
    public function __construct(protected Newsletter $newsletter, protected Subscriber $subscriber)
    {
        $this->onQueue('email');
    }

    /**
     * Get the message envelope.
     */
    public function envelope(): Envelope
    {
        return new Envelope(
            // from: new Address('example@example.com', 'Test Sender'),
            subject: $this->newsletter?->subject ?? '👀 Fresh Newsletter',
        );
    }

    /**
     * Get the message content definition.
     */
    public function content(): Content
    {
        $page = app()->request->getSchemeAndHttpHost();

        // Track views
        $trackingUrl = $page . '/track/email/views/' . $this->newsletter->id . '/' . $this->subscriber->id;
        config([
            'mail.email.tracking.image.url' => $trackingUrl
        ]);

        // Banner image
        if (isset($this->newsletter->image)) {
            config(['mail.email.banner' => $page . "/image/" . $this->newsletter->image]);
        } else {
            // Show default or uncoment to remove banner
            // config(['mail.email.banner' => null]);
        }

        foreach (Social::where('place', 'newsletter')->get() as $s) {
            config([
                'mail.email.social.' . strtolower($s->name) => $s->url ?? $page,
            ]);
        }

        $m = (new MailMessage)
            ->subject($this->newsletter->subject ?? __('👀 Fresh Newsletter'))
            ->greeting($this->replaceName($this->newsletter->title ?? __('👀 Fresh Newsletter')))
            ->lines($this->splitLines($this->newsletter->line1 ?? ''))
            ->action($this->newsletter->button ?? __('See More'), $this->newsletter->url ?? $page)
            ->lines($this->splitLines($this->newsletter->line2 ?? ''))
            ->theme('lara::theme.default')
            ->markdown('lara::email.default', [
                'code' => $this->newsletter->code ?? null,
                'date' => $this->newsletter->published_at->format('Y-m-d') ?? null,
                // Comment to hide
                // 'info' => 'Lorem ipsum dolor sit amet consectetur, adipisicing elit.',
                // 'products' => $products,
                // 'events' => $events,
                // 'news' => $news,
            ])->render();

        return new Content(
            htmlString: $m,
        );
    }

    /**
     * Get the attachments for the message.
     *
     * @return array<int, Attachment>
     */
    public function attachments(): array
    {
        return [];
    }

    /**
     * Replace mustache attribute {name}.
     *
     * @param string $str
     * @return string
     */
    public function replaceName(string $str): string
    {
        return str_ireplace('{name}', $this->subscriber->name, $str);
    }

    /**
     * Markdown multiple line format
     *
     * @param string $str
     * @return array
     */
    public function splitLines(string $str): array
    {
        return array_map(trim(...), preg_split('/\\r\\n|\\r|\\n/', $this->replaceName($str) ?? ''));
    }
}

Tracking email views

Create Newsletter and Subscriber models first. Add newsletter views column.

<?php

use Lara\Actions\TrackViewsImage;
use App\Models\Newsletter;
use App\Models\Subscriber;

Route::get('/track/email/views/{newsletter}/{subscriber}', function (
    Newsletter $newsletter, Subscriber $subscriber, TrackViewsImage $ti
) {
    // Public directory 1x1px transparent png image path
    return $ti->handle($newsletter, $subscriber, 'default/email/tracking.png');
});

Cron

Send emails from queue (or remove: implements ShouldQueue).

# Cron
crontab -e

# Test every minute
* * * * * /usr/bin/php /path-to-your-project/artisan queue:work --queue=high,medium,email,default --max-time=60 --sleep=5 > /dev/null

# Hosting every 5 min
*/10 * * * * php84 /home/username/domains/example.com/artisan queue:work --queue=high,medium,email,default --max-time=600 --sleep=5 > /dev/null

Publish Theme For Edit (optional)

# In resources/views/vendor/lara
php artisan vendor:publish --tag=lara-views --force
# In public/vendor/lara
php artisan vendor:publish --tag=lara-images --force
# In config/lara.php
php artisan vendor:publish --tag=lara-config --force

# Sample with provider package
php artisan vendor:publish --provider='Lara\LaraServiceProvider' --tag="images"

Lara Email Theme

Width to 640px

Width to 520px

atomjoy/lara 适用场景与选型建议

atomjoy/lara 是一款 基于 Blade 开发的 Composer 扩展包,目前已累计 9 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 04 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 atomjoy/lara 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 atomjoy/lara 我们能提供哪些服务?
定制开发 / 二次开发

基于 atomjoy/lara 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 9
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 39
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: Blade

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-24