Download the PHP package katzen48/laravel-twitch-eventsub without Composer
On this page you can find all versions of the php package katzen48/laravel-twitch-eventsub. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download katzen48/laravel-twitch-eventsub
More information about katzen48/laravel-twitch-eventsub
Files in katzen48/laravel-twitch-eventsub
Package laravel-twitch-eventsub
Short Description This package provides support for subscribing to Twitch EventSub. It's based on laravel-twitch and fully compatible.
License MIT
Informations about the package laravel-twitch-eventsub
Laravel Twitch EventSub Library
Introduction
This package provides support for subscribing to Twitch EventSub. It's based on laravel-twitch and fully compatible.
Features
- Create Twitch EventSub subscriptions via webhooks
- Subscribe to the received events on a per-event basis through the dedicated classes
- Define events, to subscribe to, whenever a specific model is saved to the database
Installation
First, install laravel-twitch.
Please refer to their documentation.
After laravel-twitch is installed and configured, install laravel-twitch-eventsub from composer
The config can be published with
Configuration
After you published the config, you can find it in config/twitch-eventsub.php
and it looks like this:
Consume EventSub events
Even when you don't subscribe to eventsub using this library, a route is registered, which
defaults to {APP_URL}/twitch/eventsub/webhook
. When you subscribe to EventSub and use this URL as a callback,
received events are parsed into dedicated events classes, which event listeners can subscribed to, individually.
To subscribe to an event, first create a listener with php artisan make:listener <Name>
and add the event it should
subscribe to as a parameter to the handle()
function.
To bind the listener to an event, add the listener to the $listen
array in your EventServiceProvider
There you go.
Your listener now gets incoming events of type channel.subscribe
from the Twitch EventSub.
Subscribe to Twitch EventSub on model save
Sometimes it is necessary, that newly created instances of a model trigger a subscription to the Twitch EventSub
e.g. a User logged in for the first time.
This behavior can be automated with the static SubscribesEventSubs
trait.
Add the trait SubscribesEventSubs
to your model.
Next add a static variable called $eventSubs
to your model with the events to subscribe to and the conditions,
mapped to the attributes of your model.
Now, whenever the created
event is fired on that model, a subscription to the channel.update
event tyoe is made.
The id
property of the model is automatically inserted for broadcaster_user_id
.