Download the PHP package juststeveking/laravel-webhooks without Composer
On this page you can find all versions of the php package juststeveking/laravel-webhooks. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download juststeveking/laravel-webhooks
More information about juststeveking/laravel-webhooks
Files in juststeveking/laravel-webhooks
Package laravel-webhooks
Short Description A simple webhook implementation for Laravel.
License MIT
Informations about the package laravel-webhooks
Laravel Webhooks
A simple webhook implementation for Laravel.
Installation
Publishing config
To publish the configuration file for this package, please run the following artisan command:
The config looks for a few ENV variables that you can set:
WEBHOOK_HEADER
- The header key to send the signature as, this defaults toSignature
WEBHOOK_SIGNING_KEY
- Your webhook signing key.WEBHOOK_USER_AGENT
- The user agent you want to set on your request, defaults toLaravel_Webhooks
WEBHOOK_TIMEOUT
- The request timeout you want to set for sending the webhook, defaults to 15 seconds.
Usage
Using the webhook facade all you need to pass through is the URL you want to send the webhook to.
This will return a PendingWebhook
for you to use. This will load the signing key in from your configuration.
If you need/want to set the signing key per-webhook you will need to instantiate the PendingWebhook
yourself:
The Pending Webhook has the following properties in the constructor:
url
- The URL you want to send the webhook to.signer
- An instance of the webhook signer you want to use. This must implement theSigningContract
.payload
- You can pre-pass in the payload that you want to send in your webhook. This should be anarray
.signed
- You can pre-pass in whether you want this webhook to be signed or not, the default istrue
.-signature
- You can pre-pass in the signature that you want to use to sign your Webhooks with.request
- You can pre-pass in aPendingRequest
that you want to use to send your webhooks, this is useful when you need to attach an API token to your Webhooks.
A simple example
In the below example, we are sending a webhook to https://your-url.com/
and sending it the first Post
model that we find.
A more complex example
In this example we want to send a webhook to https://your-url.com/
, again passing it the first Post
model.
However, this time we want to intercept the creation of the Request to attach the Bearer token for authentication.
We then want to dispatch the sending of this webhook to the queue.
Not signing the webhook
If you don't need to sign the webhook.
Testing
To run the test:
Credits
- Steve McDougall
- All Contributors
LICENSE
The MIT License (MIT). Please see License File for more information.