jurihub/laravel-webhooks

Laravel package to handle Webhooks
1,856 7
Install
composer require jurihub/laravel-webhooks
Latest Version:v0.1.5
License:MIT
Last Updated:Apr 6, 2021
Links: GitHub  ·  Packagist
Maintainer: jurihub

laravel-webhooks

Laravel package to handle Webhooks

Installation guide

Include the page via Composer:

composer require jurihub/laravel-webhooks

Add the Webhooks service provider to your config/app.php file in the providers array:

Jurihub\LaravelWebhooks\WebhooksServiceProvider::class

To use a Facade instead of injecting the class itself, add this to the aliases array in the same file:

'Webhooks' => Jurihub\LaravelWebhooks\WebhooksFacade::class

Publish the configuration file:

php artisan vendor:publish --provider="Jurihub\LaravelWebhooks\WebhooksServiceProvider" --tag="config"

You certainly will want to add some endpoints, list them in the targets array in config/webhooks.php

Launch the migrations (provided automatically by the ServiceProvider), that will create 2 new tables: webhooks and webhook_tries

php artisan migrate

The first attempt is sent automatically, but if you want to automatize retries, add the following schedule in your app/Console/Kernel.php file:

$schedule->call(function () {
    \Jurihub\LaravelWebhooks\Http\Controllers\Webhooks\SenderController::retry();
})->everyMinute();

To handle incoming webhooks, create a new controller, eg. App\Http\Controllers\Webhooks\ReceiverController.php

namespace App\Http\Controllers\Webhooks;

use Symfony\Component\HttpFoundation\Response;
use Jurihub\LaravelWebhooks\Http\Controllers\Webhooks\ReceiverController as BaseController;

class ReceiverController extends BaseController
{
    public function handleUserUpdated($data)
    {
        // handling $data here for type 'user.updated'
    }
}

And add the route to your routes/api.php file to receive the incoming webhooks. You may want to customize the endpoint, according to the targets listed in the config/app.php file.

Route::post('webhook', 'Webhooks\ReceiverController@handleWebhook');

Activate the webhooks' sending queue:

php artisan queue:work database --queue=webhook --tries=3

Related Packages

hopkins/gamesbase

A base library for various games.

163 0
hopkins/slackemon

A WIP attempt to implement some form of pokemon battling into slack

6 0
mpociot/captainhook

Add webhooks to your Laravel app.

8,910 335
hopkins/slack-against-humanity

A slack webhook integration that lets your team play cards against humanity

173 72
cbouvat/laravel-envol

Automatic deployment Laravel 5.2+ package with webhook Github and Bitbucket

12 4