PHP code example of katzen48 / laravel-twitch-eventsub
1. Go to this page and download the library: Download katzen48/laravel-twitch-eventsub library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
katzen48 / laravel-twitch-eventsub example snippets
return [
'callback_url' => env('TWITCH_HELIX_EVENTSUB_CALLBACK_URL', '/twitch/eventsub/webhook'), // Endpoint, the webhooks get sent to
];
namespace App\Listeners;
use katzen48\Twitch\EventSub\Events\Channel\Subscription\ChannelSubscriptionGiftEvent;
class SubscriptionListener
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle(ChannelSubscriptionGiftEvent $event)
{
// Do something
}
}
namespace App\Providers;
use App\Listeners\SubscriptionListener;use Illuminate\Auth\Events\Registered;use Illuminate\Auth\Listeners\SendEmailVerificationNotification;use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;use katzen48\Twitch\EventSub\Events\Channel\Subscription\ChannelSubscriptionGiftEvent;
class EventServiceProvider extends ServiceProvider
{
/**
* The event listener mappings for the application.
*
* @var array
*/
protected $listen = [
Registered::class => [
SendEmailVerificationNotification::class,
],
ChannelSubscriptionGiftEvent::class => [ // The Event, to subscribe to
SubscriptionListener::class, // The Listener
],
];
/**
* Register any events for your application.
*
* @return void
*/
public function boot()
{
//
}
}
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use katzen48\Twitch\EventSub\Traits\SubscribesEventSubs;
use romanzipp\Twitch\Enums\EventSubType;
class User extends Authenticatable
{
use HasFactory, Notifiable, SubscribesEventSubs;
public static array $eventSubs = [
EventSubType::CHANNEL_UPDATE => [ // The Event Type (from laravel-twitch)
'broadcaster_user_id' => 'id', // The conditions from the EventSub documentation and the model attributes
],
];
protected $keyType = 'string';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'id',
'name',
'email',
'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'id' => 'string',
'email_verified_at' => 'datetime',
];
}
shell
php artisan vendor:publish --tag=config
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.