59 lines
1.3 KiB
PHP
59 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class Alert extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'website_id',
|
|
'name',
|
|
'metric',
|
|
'condition',
|
|
'threshold',
|
|
'period',
|
|
'channel',
|
|
'is_active',
|
|
'last_triggered_at',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'threshold' => 'decimal:2',
|
|
'is_active' => 'boolean',
|
|
'last_triggered_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
public function website(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Website::class);
|
|
}
|
|
|
|
public function notifications(): HasMany
|
|
{
|
|
return $this->hasMany(AlertNotification::class);
|
|
}
|
|
|
|
public static array $metrics = [
|
|
'page_views' => 'Page Views',
|
|
'visitors' => 'Unique Visitors',
|
|
'sessions' => 'Sessions',
|
|
'bounce_rate' => 'Bounce Rate',
|
|
];
|
|
|
|
public static array $conditions = [
|
|
'above' => 'goes above',
|
|
'below' => 'drops below',
|
|
'change_up' => '% increase exceeds',
|
|
'change_down' => '% decrease exceeds',
|
|
];
|
|
}
|