ultimatepos/Modules/IntegrationHub/Models/IhWebhookEndpoint.php

42 lines
958 B
PHP

<?php
namespace Modules\IntegrationHub\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class IhWebhookEndpoint extends Model
{
protected $table = 'ih_webhook_endpoints';
protected $guarded = ['id'];
protected $casts = [
'events' => 'array',
'is_active' => 'boolean',
'last_triggered_at' => 'datetime',
];
public function deliveries(): HasMany
{
return $this->hasMany(IhWebhookDelivery::class, 'endpoint_id');
}
public function scopeForBusiness($query, int $businessId)
{
return $query->where('business_id', $businessId);
}
public function scopeActive($query)
{
return $query->where('is_active', true);
}
public function listensTo(string $eventName): bool
{
$events = $this->events ?? [];
return in_array($eventName, $events, true) || in_array('*', $events, true);
}
}