Files
KanbanGit/app/Models/NotificationAction.php
T

63 lines
1.6 KiB
PHP

<?php
namespace App\Models;
use App\Enums\NotificationChannel;
use App\Enums\NotificationEventType;
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',
'message_template',
'name',
'project_id',
])]
#[Hidden(['delivery_url'])]
class NotificationAction extends Model
{
/** @use HasFactory<NotificationActionFactory> */
use HasFactory;
/**
* @return array<string, string>
*/
protected function casts(): array
{
return [
'channel' => NotificationChannel::class,
'channel_configuration' => 'array',
'delivery_url' => 'encrypted',
'enabled' => 'boolean',
'event_type' => NotificationEventType::class,
];
}
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);
}
}