Files
KanbanGit/app/Models/NotificationAction.php
T
Koda 2390daf2de
linter / quality (pull_request) Successful in 1m26s
tests / ci (8.4) (pull_request) Successful in 1m49s
Move remaining project metadata ownership to templates
2026-06-05 20:31:38 +00:00

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);
}
}