PHPackages                             minkbear/captainhook - 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. [API Development](/categories/api)
4. /
5. minkbear/captainhook

ActiveLibrary[API Development](/categories/api)

minkbear/captainhook
====================

Add webhooks to your Laravel app.

3.4.4(7y ago)016MITPHPPHP &gt;=5.4.0

Since Oct 30Pushed 7y ago1 watchersCompare

[ Source](https://github.com/minkbear/captainhook)[ Packagist](https://packagist.org/packages/minkbear/captainhook)[ Docs](http://github.com/mpociot/captainhook)[ RSS](/packages/minkbear-captainhook/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (7)Versions (34)Used By (0)

[![Captain Hook](https://camo.githubusercontent.com/4ec9024f785d5e6711a183bacc8f9d411a15bc35e6fb39f5e985451a3031c14a/687474703a2f2f7777772e6d617263656c706f63696f742e636f6d2f6769742f686f6f6b2e706e67)](https://camo.githubusercontent.com/4ec9024f785d5e6711a183bacc8f9d411a15bc35e6fb39f5e985451a3031c14a/687474703a2f2f7777772e6d617263656c706f63696f742e636f6d2f6769742f686f6f6b2e706e67)

\# Captain Hook ## Add Webhooks to your Laravel app, arrr [![image](https://camo.githubusercontent.com/ad7ddff20e17b57220a0c48dc267e2e172090a6b6458090257ef439b4f65372a/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d706f63696f742f6361707461696e686f6f6b2e7376673f7374796c653d666c6174)](https://camo.githubusercontent.com/ad7ddff20e17b57220a0c48dc267e2e172090a6b6458090257ef439b4f65372a/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d706f63696f742f6361707461696e686f6f6b2e7376673f7374796c653d666c6174)[![image](https://camo.githubusercontent.com/22321581d368e52273554ab8d8ed297c64c3cb93f744a28a1dfb8299e7f32e80/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d706f63696f742f6361707461696e686f6f6b2e7376673f7374796c653d666c6174)](https://camo.githubusercontent.com/22321581d368e52273554ab8d8ed297c64c3cb93f744a28a1dfb8299e7f32e80/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d706f63696f742f6361707461696e686f6f6b2e7376673f7374796c653d666c6174)[![codecov.io](https://camo.githubusercontent.com/169fa0d99d9878a8401d77720170a656a6228c9fb8c45beea9c2576d6500a00a/68747470733a2f2f636f6465636f762e696f2f6769746875622f6d706f63696f742f6361707461696e686f6f6b2f636f7665726167652e7376673f6272616e63683d6d6173746572)](https://codecov.io/github/mpociot/captainhook?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/477281aa3a17b56d35403767ca176b11395f09d53e65fa8975db565da56002ff/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d706f63696f742f6361707461696e686f6f6b2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mpociot/captainhook/?branch=master)[![Build Status](https://camo.githubusercontent.com/4fb436611a40bc5feef49b7b30fbe1c6b685d267eff83569685fbb63af7741c5/68747470733a2f2f7472617669732d63692e6f72672f6d706f63696f742f6361707461696e686f6f6b2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/mpociot/captainhook)[![StyleCI](https://camo.githubusercontent.com/64c3b451993cafb1f04409f3f88ee6946e8b3ac98afe68ebd9cfed8de9ac0019/68747470733a2f2f7374796c6563692e696f2f7265706f732f34353231363235352f736869656c64)](https://styleci.io/repos/45216255)

Implement multiple webhooks into your Laravel app using the Laravel Event system.

```
A webhook is a method of altering the behavior of a web application, with custom callbacks.
These callbacks may be managed by third-party users and developers who may not necessarily
be affiliated with the originating application.

```

Examples
--------

[](#examples)

```
php artisan hook:add http://www.myapp.com/hooks/ '\App\Events\PodcastWasPurchased'
php artisan hook:add http://www.myapp.com/hooks/ 'eloquent.saved: \App\User'
```

```
Webhook::create([
    "url" => Input::get("url"),
    "event" => "\\App\\Events\\MyEvent",
    "tenant_id" => Auth::id()
]);
```

Contents
--------

[](#contents)

- [Installation](#installation)
- [Implementation](#implementation)
- [Usage](#usage)
    - [Spark support](#spark)
    - [Custom event listeners](#listeners)
    - [Add new webhooks](#add)
    - [Delete existing webhooks](#delete)
    - [List all active webhooks](#list)
    - [Receiving a webhook notification](#webhook)
    - [Webhook logging](#logging)
    - [Using webhooks with multi tenancy](#tenant)
- [License](#license)

\## Installation In order to add CaptainHook to your project, just add

```
"mpociot/captainhook": "~2.0"

```

to your `composer.json`'s `require` block. Then run `composer install` or `composer update`.

Or run `composer require mpociot/captainhook ` if you prefer that.

Then in your `config/app.php` add

```
Mpociot\CaptainHook\CaptainHookServiceProvider::class

```

to the `providers` array.

Publish and run the migration to create the "webhooks" table that will hold all installed webhooks.

```
php artisan vendor:publish --provider="Mpociot\CaptainHook\CaptainHookServiceProvider"

php artisan migrate
```

\## Usage The CaptainHook service provider listens for any `eloquent.*` events.

If the package finds a configured webhook for an event, it will make a `POST` request to the specified URL.

Webhook data is sent as JSON in the POST request body. The full event object is included and can be used directly, after parsing the JSON body.

**Example**

Let's say you want to have a webhook that gets called every time your User model gets updated.

The event that gets called from Laravel will be:

`eloquent.updated: \App\User`

So this will be the event you want to listen for.

\### Add new webhooks If you know which event you want to listen to, you can add a new webhook by using the `hook:add` artisan command.

This command takes two arguments:

- The webhook URL that will receive the POST requests
- The event name. This could either be one of the `eloquent.*` events, or one of your custom events.

```
php artisan hook:add http://www.myapp.com/hook/ 'eloquent.saved: \App\User'
```

You can also add multiple webhooks for the same event, as all configured webhooks will get called asynchronously.

\### Delete existing webhooks To remove an existing webhook from the system, use the `hook:delete` command. This command takes the webhook ID as an argument.

```
php artisan hook:delete 2
```

\### List all active webhooks To list all existing webhooks, use the `hook:list` command.

It will output all configured webhooks in a table.

\### Spark Install this package like stated in the [Installation section](#installation), then follow the [Spark installation instructions](spark.md).

\### Custom event listeners All listeners are defined in the config file located at `config/captain_hook.php`.

\### Receiving a webhook notification To receive the event data in your configured webhook, use:

```
// Retrieve the request's body and parse it as JSON
$input = @file_get_contents("php://input");
$event_json = json_decode($input);

// Do something with $event_json
```

\### Webhook logging Starting with version 2.0, this package allows you to log the payload and response of the triggered webhooks.

> **NOTE:** A non-blocking queue driver (not `sync`) is highly recommended. Otherwise your application will need to wait for the webhook execution.

You can configure how many logs will be saved **per webhook** (Default 50).

This value can be modified in the configuration file `config/captain_hook.php`.

\### Using webhooks with multi tenancy Sometimes you don't want to use system wide webhooks, but rather want them scoped to a specific "tenant". This could be bound to a user or a team.

The webhook table has a field `tenant_id` for this purpose. So if you want your users to be able to add their own webhooks, you won't use the artisan commands to add webhooks to the database, but add them on your own.

To add a webhook that is scoped to the current user, you could do for example:

```
Webhook::create([
    "url" => Input::get("url"),
    "event" => "\\App\\Events\\MyEvent",
    "tenant_id" => Auth::id()
]);
```

Now when you fire this event, you want to call the webhook only for the currently logged in user.

In order to filter the webhooks, modify the `filter` configuration value in the `config/captain_hook.php` file. This filter is a Laravel collection filter.

To return only the webhooks for the currently logged in user, it might look like this:

```
'filter' => function( $webhook ){
    return $webhook->tenant_id == Auth::id();
},
```

\## License CaptainHook is free software distributed under the terms of the MIT license.

'Day 02: Table, Lamp &amp; Treasure Map' image licensed under [Creative Commons 2.0](https://creativecommons.org/licenses/by/2.0/) - Photo from [stevedave](https://www.flickr.com/photos/stevedave/4153323914)

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~42 days

Recently: every ~6 days

Total

26

Last Release

2803d ago

Major Versions

1.0.4 → 2.0.02016-01-27

2.2.0 → 3.0.02016-04-16

PHP version history (2 changes)1.0.0PHP &gt;=5.3.0

1.0.1PHP &gt;=5.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/a3a580b3db0dc14be9b928196f582aed0aeee3f1f198c42757219fb6b7daa490?d=identicon)[minkbear](/maintainers/minkbear)

---

Top Contributors

[![mpociot](https://avatars.githubusercontent.com/u/804684?v=4)](https://github.com/mpociot "mpociot (59 commits)")[![phroggyy](https://avatars.githubusercontent.com/u/7256451?v=4)](https://github.com/phroggyy "phroggyy (19 commits)")[![lucasmichot](https://avatars.githubusercontent.com/u/513603?v=4)](https://github.com/lucasmichot "lucasmichot (18 commits)")[![ferranfg](https://avatars.githubusercontent.com/u/195239?v=4)](https://github.com/ferranfg "ferranfg (9 commits)")[![dducro](https://avatars.githubusercontent.com/u/2156884?v=4)](https://github.com/dducro "dducro (5 commits)")[![minkbear](https://avatars.githubusercontent.com/u/233714?v=4)](https://github.com/minkbear "minkbear (5 commits)")[![patrickhoogkamer](https://avatars.githubusercontent.com/u/1894838?v=4)](https://github.com/patrickhoogkamer "patrickhoogkamer (3 commits)")[![giannidhooge](https://avatars.githubusercontent.com/u/6651325?v=4)](https://github.com/giannidhooge "giannidhooge (2 commits)")[![tiagoalves](https://avatars.githubusercontent.com/u/215495?v=4)](https://github.com/tiagoalves "tiagoalves (2 commits)")[![svenluijten](https://avatars.githubusercontent.com/u/11269635?v=4)](https://github.com/svenluijten "svenluijten (1 commits)")[![vmitchell85](https://avatars.githubusercontent.com/u/1248035?v=4)](https://github.com/vmitchell85 "vmitchell85 (1 commits)")[![MatissJanis](https://avatars.githubusercontent.com/u/886567?v=4)](https://github.com/MatissJanis "MatissJanis (1 commits)")[![Jeroen-G](https://avatars.githubusercontent.com/u/1116853?v=4)](https://github.com/Jeroen-G "Jeroen-G (1 commits)")[![shoully](https://avatars.githubusercontent.com/u/680153?v=4)](https://github.com/shoully "shoully (1 commits)")

---

Tags

laraveleventswebhookswebhookHOOK

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/minkbear-captainhook/health.svg)

```
[![Health](https://phpackages.com/badges/minkbear-captainhook/health.svg)](https://phpackages.com/packages/minkbear-captainhook)
```

###  Alternatives

[mpociot/captainhook

Add webhooks to your Laravel app.

3358.9k](/packages/mpociot-captainhook)[irazasyed/telegram-bot-sdk

The Unofficial Telegram Bot API PHP SDK

3.3k4.5M84](/packages/irazasyed-telegram-bot-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
