75 lines
1.9 KiB
PHP
75 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\NotificationChannel;
|
|
use App\Enums\NotificationEventType;
|
|
use App\Models\Concerns\SyncsProjectTemplateOwnership;
|
|
use Database\Factories\NotificationActionFactory;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
#[Fillable([
|
|
'channel',
|
|
'channel_configuration',
|
|
'delivery_url',
|
|
'enabled',
|
|
'event_type',
|
|
'filters',
|
|
'message_template',
|
|
'name',
|
|
'project_id',
|
|
'project_template_id',
|
|
])]
|
|
#[Hidden(['delivery_url'])]
|
|
class NotificationAction extends Model
|
|
{
|
|
/** @use HasFactory<NotificationActionFactory> */
|
|
use HasFactory;
|
|
use SyncsProjectTemplateOwnership;
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'channel' => NotificationChannel::class,
|
|
'channel_configuration' => 'array',
|
|
'delivery_url' => 'encrypted',
|
|
'enabled' => 'boolean',
|
|
'event_type' => NotificationEventType::class,
|
|
'filters' => 'array',
|
|
];
|
|
}
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::saving(function (self $notificationAction): void {
|
|
$notificationAction->syncProjectTemplateOwnership();
|
|
});
|
|
}
|
|
|
|
public function scopeEnabled(Builder $query): Builder
|
|
{
|
|
return $query->where('enabled', true);
|
|
}
|
|
|
|
public function deliveryLogs(): HasMany
|
|
{
|
|
return $this->hasMany(NotificationDeliveryLog::class)
|
|
->orderByDesc('created_at')
|
|
->orderByDesc('id');
|
|
}
|
|
|
|
public function project(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Project::class);
|
|
}
|
|
}
|