Add notification action foundation
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user