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

Filament Webhook Server Laravel Package

marjose123/filament-webhook-server

Add a webhook server to your Filament app: receive, validate, and manage incoming webhooks with a clean admin UI. Configure endpoints and events, inspect payloads, and monitor delivery from your Filament panel—all in a Laravel-friendly package.

View on GitHub
Deep Wiki
Context7
## Getting Started

### Minimal Setup
1. **Installation**:
   ```bash
   composer require marjose123/filament-webhook-server
   php artisan vendor:publish --tag="filament-webhook-server-migrations"
   php artisan migrate
  1. Register Plugin: Add the plugin to your Filament panel configuration (app/Providers/Filament/AdminPanelProvider.php):

    use Marjose123\FilamentWebhookServer\WebhookPlugin;
    
    public function panel(Panel $panel): Panel
    {
        return $panel
            ->plugins([
                WebhookPlugin::make()->enablePlugin(),
            ]);
    }
    
  2. First Use Case:

    • Access the Webhook Server plugin in your Filament admin panel.
    • Create a new webhook by selecting a model (e.g., User) and configuring the target URL, events (created, updated, deleted), and payload format (Summary, All, or Custom).

Implementation Patterns

Core Workflow

  1. Model Integration:

    • All Eloquent models are automatically available for webhook events.
    • Exclude/include specific models via excludedModels()/includeModels() in the plugin configuration:
      WebhookPlugin::make()
          ->includeModels([\App\Models\Order::class])
          ->excludedModels([\App\Models\Draft::class])
          ->enablePlugin()
      
  2. Payload Customization:

    • Default Payloads: Use Summary (basic fields) or All (full model data).
    • Custom Payloads: Implement the Webhookable interface in your model:
      use Marjose123\FilamentWebhookServer\Contracts\Webhookable;
      
      class Order extends Model implements Webhookable
      {
          public function toWebhookPayload(): array
          {
              return [
                  'order_id' => $this->id,
                  'total' => $this->amount,
                  'customer_email' => $this->user->email,
              ];
          }
      }
      
  3. Event Handling:

    • Webhooks trigger on created, updated, and deleted events by default.
    • Extend functionality by listening to model events in AppServiceProvider:
      public function boot()
      {
          \App\Models\User::created(function ($user) {
              // Custom logic before webhook dispatch
          });
      }
      
  4. API Access:

    • Enable API routes for programmatic webhook management:
      WebhookPlugin::make()->enableApiRoutes()->enablePlugin()
      
    • Use the API to create/update webhooks via HTTP requests (e.g., POST /filament/webhooks).
  5. Logging and History:

    • Enable webhook logs via keepLogs():
      WebhookPlugin::make()->keepLogs()->enablePlugin()
      
    • View logs in the Webhook History tab within the plugin.

Advanced Patterns

  1. Dynamic Configuration:

    • Override default polling intervals (e.g., for high-frequency events):
      WebhookPlugin::make()->polling(5)->enablePlugin() // Poll every 5 seconds
      
  2. Multi-Tenant Support:

    • Use Filament’s clusters to isolate webhook configurations per tenant:
      WebhookPlugin::make()->cluster('tenant-cluster')->enablePlugin()
      
  3. Testing:

    • Mock webhook deliveries in tests using Laravel’s Http::fake():
      use Illuminate\Support\Facades\Http;
      
      public function test_webhook_delivery()
      {
          Http::fake();
          $user = User::create([...]);
          // Assert webhook was called
      }
      
  4. Security:

    • Validate webhook signatures if using external services (e.g., Stripe):
      // In your webhook handler middleware
      public function handle(Request $request, Closure $next)
      {
          if (!$this->validateSignature($request)) {
              abort(403);
          }
          return $next($request);
      }
      

Gotchas and Tips

Common Pitfalls

  1. Model Registration Issues:

    • Problem: Models not appearing in the webhook dropdown.
    • Fix: Ensure models are properly namespaced and autoloaded. Re-publish migrations if using custom tables:
      php artisan vendor:publish --tag="filament-webhook-server-migrations" --force
      php artisan migrate:fresh
      
  2. Payload Serialization Errors:

    • Problem: Non-serializable data (e.g., relationships) in custom payloads.
    • Fix: Explicitly cast or resolve relationships in toWebhookPayload():
      public function toWebhookPayload(): array
      {
          return [
              'user_email' => $this->user?->email ?? null,
          ];
      }
      
  3. Event Timing:

    • Problem: Webhooks firing out of order or missing events.
    • Fix: Use Laravel’s queue for async processing:
      // In your model observer
      public function created(User $user)
      {
          dispatch(new DispatchWebhook($user));
      }
      
  4. API Route Conflicts:

    • Problem: enableApiRoutes() clashing with existing routes.
    • Fix: Prefix routes or use middleware to restrict access:
      WebhookPlugin::make()
          ->enableApiRoutes()
          ->apiPrefix('admin/webhooks')
          ->enablePlugin()
      
  5. Performance:

    • Problem: Slow response times for webhook deliveries.
    • Fix: Limit payload size or use Summary format. For bulk operations, batch events:
      // In your webhook service
      public function dispatchBatch(array $events)
      {
          foreach (array_chunk($events, 50) as $chunk) {
              Http::post($url, ['events' => $chunk]);
          }
      }
      

Debugging Tips

  1. Log Webhook Payloads:

    • Enable logging via keepLogs() and check the Webhook History tab for raw payloads.
  2. Test Locally:

    • Use tools like ngrok to expose local endpoints for testing:
      ngrok http 8000
      
    • Configure webhooks to point to https://your-ngrok-url.ngrok.io/webhook-endpoint.
  3. Validate Signatures:

    • For security, add signature validation to your webhook endpoint:
      public function handleStripeWebhook(Request $request)
      {
          $payload = $request->getContent();
          $sigHeader = $request->header('Stripe-Signature');
          if (!\Stripe\Webhook::constructEvent($payload, $sigHeader, config('services.stripe.webhook_secret'))) {
              abort(400);
          }
          // Process event
      }
      
  4. Monitor Failures:

    • Set up a Laravel Horizon job to retry failed webhooks:
      // In your webhook service
      public function sendWebhook($url, $payload)
      {
          try {
              Http::post($url, $payload);
          } catch (\Exception $e) {
              RetryFailedWebhook::dispatch($url, $payload, $e->getMessage());
          }
      }
      

Extension Points

  1. Custom Pages:

    • Replace default pages (e.g., for advanced filtering):
      WebhookPlugin::make()
          ->customPageUsing(
              webhookPage: \App\Filament\Pages\CustomWebhookPage::class,
              webhookHistoryPage: \App\Filament\Pages\CustomHistoryPage::class
          )
          ->enablePlugin()
      
  2. Event Extensions:

    • Add custom events (e.g., published for a Post model):
      // In your model observer
      public function published(Post $post)
      {
          event(new WebhookEvent($post, 'published'));
      }
      
  3. Middleware:

    • Add middleware to webhook routes for authentication/authorization:
      Route::middleware(['auth:sanctum', 'webhook.verify'])->post('/webhooks', [WebhookController::class, 'store']);
      
  4. Translations:

    • Extend translations for multilingual support:
      // In your language provider
      public function boot()
      {
          $this->loadTranslationsFrom(__DIR__.'/lang', 'filament-webhook-server');
      }
      

Configuration Quirks

  1. Polling Intervals:

    • Set realistic intervals (e.g., 10 seconds) to avoid rate limits or excessive load.
  2. SSL Verification:

    • Disable SSL verification for testing only (not production):
      // In config/filament-webhook-server.php
      'webhook' =>
      
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.
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
spatie/mailcoach-vapor