shelfwood/laravel-n8n
Composer 安装命令:
composer require shelfwood/laravel-n8n
包简介
Tag-based n8n webhook integration for Laravel — fire events, auto-dispatch to matching n8n workflows
README 文档
README
Tag-based n8n webhook integration for Laravel. Fire events in your app, auto-dispatch to matching n8n workflows. Zero configuration per workflow — just tag your n8n workflows and the package handles the rest.
How it works
- Add the
HasN8nTriggertrait to any Laravel Event class - The event auto-generates a tag from its class name (e.g.
OrderCompleted→app:order-completed) - When the event fires, the package finds all active n8n workflows tagged with
app:order-completed - It POSTs the event payload to each workflow's webhook URL
- Fire-and-forget — your app doesn't depend on n8n being available
Installation
composer require shelfwood/laravel-n8n
The service provider auto-discovers. Publish the config:
php artisan vendor:publish --tag=n8n-config
Add to your .env:
N8N_URL=https://your-n8n-instance.com N8N_API_KEY=your-api-key
Usage
1. Create an event with the trait
use Illuminate\Foundation\Events\Dispatchable; use Shelfwood\N8n\Traits\HasN8nTrigger; class OrderCompleted { use Dispatchable, HasN8nTrigger; public function __construct( public string $orderId, public float $total, ) {} public function toArray(): array { return [ 'order_id' => $this->orderId, 'total' => $this->total, ]; } }
2. Fire the event normally
event(new OrderCompleted($order->id, $order->total));
3. Create an n8n workflow with matching tag
In your n8n instance, create a workflow with:
- A Webhook trigger node
- A tag matching the event:
app:order-completed
The package finds the workflow by tag and POSTs:
{
"event": "App\\Events\\OrderCompleted",
"timestamp": "2026-04-13T00:00:00+00:00",
"tags": ["app:order-completed"],
"data": {
"order_id": "abc-123",
"total": 99.95
}
}
Custom tags
Override the auto-generated tag:
$event = new OrderCompleted($id, $total); $event->setN8nTags(['custom:high-value-order']); event($event);
Filament Status Page
If your project uses Filament, register the status page in your AdminPanelProvider:
use Shelfwood\N8n\Filament\Pages\N8nStatus; ->pages([ N8nStatus::class, ])
This shows:
- n8n connection health
- All discovered events with their tags
- Which n8n workflows are connected to which events
Configuration
// config/n8n.php return [ 'api' => [ 'url' => env('N8N_URL', ''), 'key' => env('N8N_API_KEY', ''), ], 'workflows' => [ 'timeout' => (int) env('N8N_WORKFLOW_TIMEOUT', 10), 'retry_attempts' => 3, 'retry_delay' => 5, // Cache TTL for the workflow list (seconds). Every event dispatch // would otherwise refetch the full workflow set. 0 disables. 'cache_ttl' => (int) env('N8N_WORKFLOWS_CACHE_TTL', 60), ], // Tag prefix for auto-generated event tags. Override per environment to // discriminate workflows on a single shared n8n (`staging:`, `prod:`). 'tag_prefix' => env('N8N_TAG_PREFIX', 'app:'), // Directories scanned by the Filament status page 'event_directories' => [ 'app/Events', ], ];
Domain-driven layouts
If your application stores events outside app/ (e.g. a src/Domain/*/Events
layout under a Domain\ PSR-4 root), override event_directories:
'event_directories' => [ 'src/Domain/*/Events', ],
The status page resolves class names from composer.json PSR-4, so any
namespace mapped there works — no extra registration needed.
Multi-environment tag separation
Two apps sharing one n8n? Set N8N_TAG_PREFIX=staging: on staging and
N8N_TAG_PREFIX=prod: on production. Tag your workflows accordingly and the
two streams stay isolated without duplicated workflows.
Graceful degradation
- No
N8N_URL→ events fire normally but no webhooks are dispatched - n8n is down → the queued job retries 3 times, then logs and moves on
- No matching workflow → the job silently returns (no error)
Testing
In your test suite, set N8N_URL to empty in phpunit.xml:
<env name="N8N_URL" value=""/>
This disables webhook dispatch. Your n8n-specific tests can override:
config(['n8n.api.url' => 'https://n8n.test']); Queue::fake(); event(new OrderCompleted('123', 50.00)); Queue::assertPushed(DispatchN8nWebhook::class);
License
MIT
shelfwood/laravel-n8n 适用场景与选型建议
shelfwood/laravel-n8n 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 636 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「events」 「laravel」 「automation」 「webhooks」 「filament」 「n8n」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 shelfwood/laravel-n8n 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 shelfwood/laravel-n8n 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 shelfwood/laravel-n8n 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Библиотека для реализаций паттерна Pub/Sub
Wireless Cross-Component Communication
A powerful event calendar Tool for Laravel's Nova 5.
Command-line utility for Vtiger CRM.
Historical accounting for contacts
Command bus implementation: Commands and domain events
统计信息
- 总下载量: 636
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 36
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-12