29 lines
762 B
PHP
29 lines
762 B
PHP
<?php
|
|
|
|
namespace Modules\Api\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
final class Webhook extends Model
|
|
{
|
|
protected $fillable = ['site_id', 'name', 'url', 'secret', 'events', 'is_active', 'failure_count', 'last_triggered_at'];
|
|
|
|
protected $hidden = ['secret'];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return ['events' => 'array', 'is_active' => 'boolean', 'last_triggered_at' => 'datetime'];
|
|
}
|
|
|
|
public function deliveries(): HasMany
|
|
{
|
|
return $this->hasMany(WebhookDelivery::class);
|
|
}
|
|
|
|
public function subscribesTo(string $event): bool
|
|
{
|
|
return in_array('*', $this->events ?: [], true) || in_array($event, $this->events ?: [], true);
|
|
}
|
|
}
|