1. Go to this page and download the library: Download oriceon/laravel-n8n-bridge library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
oriceon / laravel-n8n-bridge example snippets
namespace App\N8n;
use Oriceon\N8nBridge\DTOs\N8nPayload;
use Oriceon\N8nBridge\Inbound\N8nInboundHandler;
final class InvoicePaidHandler extends N8nInboundHandler
{
public function handle(N8nPayload $payload): void
{
$invoice = Invoice::findOrFail($payload->red|date',
];
}
}
use Oriceon\N8nBridge\Facades\N8nBridge;
// By workflow name
N8nBridge::trigger('order-shipped', [
'order_id' => $order->id,
'shipped_at' => now()->toIso8601String(),
]);
// Sync (waits for HTTP response)
N8nBridge::trigger($workflow, $payload, async: false);
use Oriceon\N8nBridge\Concerns\TriggersN8nOnEvents;
class Invoice extends Model
{
use TriggersN8nOnEvents;
protected array $n8nTriggers = [
'created' => 'invoice-created',
'updated' => [
'workflow' => 'invoice-status-changed',
'only_when' => ['status', 'paid_at'],
],
];
}
use Oriceon\N8nBridge\Enums\WebhookMode;
N8nWorkflow::find($id)->update([
'webhook_mode' => WebhookMode::Auto, // default — /webhook-test in dev, /webhook in prod
// 'webhook_mode' => WebhookMode::Production, // always /webhook
// 'webhook_mode' => WebhookMode::Test, // always /webhook-test
]);
use Oriceon\N8nBridge\Auth\WebhookAuthService;
use Oriceon\N8nBridge\Enums\WebhookAuthType;
N8nWorkflow::where('name', 'order-shipped')->update([
'auth_type' => WebhookAuthType::HmacSha256, // or HeaderToken / Bearer
'auth_key' => WebhookAuthService::generateKey(),
]);
N8nWorkflow::where('name', 'bulk-sync')
->update(['rate_limit' => 10]); // 10 req/min for this workflow
final class GetInvoiceTool extends N8nToolHandler
{
public function get(N8nToolRequest $request): N8nToolResponse
{
return N8nToolResponse::item(
Invoice::findOrFail($request->