new funcionality
This commit is contained in:
36
app/Models/WebhookEndpoint.php
Normal file
36
app/Models/WebhookEndpoint.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Laravel\Passport\Client;
|
||||
|
||||
#[Fillable(['client_id', 'url', 'secret', 'events', 'active'])]
|
||||
#[Hidden(['secret'])]
|
||||
class WebhookEndpoint extends Model
|
||||
{
|
||||
protected $casts = [
|
||||
'secret' => 'encrypted',
|
||||
'events' => 'array',
|
||||
'active' => 'boolean',
|
||||
];
|
||||
|
||||
public function client(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Client::class);
|
||||
}
|
||||
|
||||
public function deliveries(): HasMany
|
||||
{
|
||||
return $this->hasMany(WebhookDelivery::class);
|
||||
}
|
||||
|
||||
public function subscribesTo(string $event): bool
|
||||
{
|
||||
return $this->active && in_array($event, $this->events ?? [], true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user