PHPackages                             mvdnbrk/laravel-postmark-webhooks - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. mvdnbrk/laravel-postmark-webhooks

ActiveLibrary

mvdnbrk/laravel-postmark-webhooks
=================================

Handle Postmark webhooks in a Laravel application.

v1.7.0(4y ago)2644.4k↓50%12[1 issues](https://github.com/mvdnbrk/laravel-postmark-webhooks/issues)[1 PRs](https://github.com/mvdnbrk/laravel-postmark-webhooks/pulls)MITPHPPHP ^7.2 || ^8.0

Since Sep 22Pushed 1y ago3 watchersCompare

[ Source](https://github.com/mvdnbrk/laravel-postmark-webhooks)[ Packagist](https://packagist.org/packages/mvdnbrk/laravel-postmark-webhooks)[ Docs](https://github.com/mvdnbrk/laravel-postmark-webhooks)[ GitHub Sponsors](https://github.com/mvdnbrk)[ RSS](/packages/mvdnbrk-laravel-postmark-webhooks/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (23)Used By (0)

[![Postmark Inbound](https://camo.githubusercontent.com/bc1bd67d420c959e59946436cc159be4443e56c4620a1287d9b1c49748a982d6/68747470733a2f2f706f73746d61726b6170702e636f6d2f696d616765732f6c6f676f2e737667)](https://postmarkapp.com)

Handle Postmark webhooks in a Laravel application
=================================================

[](#handle-postmark-webhooks-in-a-laravel-application)

[![Latest Version on Packagist](https://camo.githubusercontent.com/d8d325cc60b30e6555b57ab7ab29900a673f430babce62fd9b8fa04991bc2deb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d76646e62726b2f6c61726176656c2d706f73746d61726b2d776562686f6f6b732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mvdnbrk/laravel-postmark-webhooks)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Tests](https://camo.githubusercontent.com/f6502f122e1d05d9aa548e0366cf6e648f64f34b83e2c509db3b6f5aaabf1132/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6d76646e62726b2f6c61726176656c2d706f73746d61726b2d776562686f6f6b732f74657374732f6d61696e3f6c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/mvdnbrk/laravel-postmark-webhooks/actions?query=workflow%3Atests)[![StyleCI](https://camo.githubusercontent.com/dfbb775596120a1c21fcf529763c863f0fa2cdbdf33a66fc20f7dfc7420f02e6/68747470733a2f2f7374796c6563692e696f2f7265706f732f3134393438373937392f736869656c643f6272616e63683d6d61696e)](https://styleci.io/repos/149487979)[![Total Downloads](https://camo.githubusercontent.com/eb7226777e0b8c9bd7ffde68f351cfb147ca331ef538d38d30208252d0d0f2c6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d76646e62726b2f6c61726176656c2d706f73746d61726b2d776562686f6f6b732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mvdnbrk/laravel-postmark-webhooks)

Postmark can send out several webhooks to *your* application when an event occurs.
This way Postmark is able to immediately notify you when something new occurs.

This package can help you handle those webhooks.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require mvdnbrk/laravel-postmark-webhooks
```

This package will log all incoming webhooks to the database by default.
Run the migrations to create a `postmark_webhook_logs` table in the database:

```
php artisan migrate
```

> If you want to disable database logging you can set `POSTMARK_WEBHOOKS_LOG_ENABLED=false` in your `.env` file.

Setup webhooks with Postmark
----------------------------

[](#setup-webhooks-with-postmark)

Visit the [servers](https://account.postmarkapp.com/servers) page on your [Postmark account](https://account.postmarkapp.com/). Choose the server you want to setup webhooks for.
Go to `settings` &gt; `webhooks` &gt; `add webbook`.

This package will register a route where Postmark can post their webhooks to: `/api/webhooks/postmark`.

Fill in your webhook URL: `https:///api/webhooks/postmark`
Pick the events Postmark should send to you and save the webhook.
You are ready to receive webhook notifications from Postmark!

> You may change the `/api/webhooks/postmark` endpoint to anything you like.
> You can do this by changing the `path` key in the `config/postmark-webooks.php` file.

Protection of your webhook
--------------------------

[](#protection-of-your-webhook)

This package protects your webhook automatically by only allowing requests from the [IP range](https://postmarkapp.com/support/article/800-ips-for-firewalls#webhooks) that Postmark uses.

Usage
-----

[](#usage)

Postmark can send out several event types by posting a webhook.
You can find the [full list of webhooks](https://postmarkapp.com/developer/webhooks/webhooks-overview) in the Postmark documentation.

All webhook requests will be logged in the `postmark_webhook_logs` table.
The table has a `payload` column where the entire payload of the incoming webhook is saved.
The ID Postmark assigned to the original message will be saved in the `message_id` column,
the event type will be stored in the `record_type` column and the email address as well in the `email` column.

> Note that event types will be converted to `snake_case`.
> For example `SpamComplaint` will be saved as `spam_complaint`.

### Events

[](#events)

Whenever a webhook call comes in, this package will fire a `PostmarkWebhookCalled` event.
You may register an event listener in the `EventServiceProvider`:

```
/**
 * The event listener mappings for the application.
 *
 * @var array
 */
protected $listen = [
    PostmarkWebhookCalled::class => [
        YourListener::class,
    ],
];
```

Example of a listener:

```
