2026-01-14 21:46:04 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
2026-01-17 13:46:20 +02:00
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
2026-01-14 21:46:04 +02:00
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
|
|
|
use Illuminate\Notifications\Notifiable;
|
2026-01-17 16:42:43 +02:00
|
|
|
use Laravel\Sanctum\HasApiTokens;
|
2026-01-14 21:46:04 +02:00
|
|
|
|
|
|
|
|
class User extends Authenticatable
|
|
|
|
|
{
|
|
|
|
|
/** @use HasFactory<\Database\Factories\UserFactory> */
|
2026-01-17 16:42:43 +02:00
|
|
|
use HasFactory, Notifiable, HasApiTokens;
|
2026-01-14 21:46:04 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The attributes that are mass assignable.
|
|
|
|
|
*
|
|
|
|
|
* @var list<string>
|
|
|
|
|
*/
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'name',
|
|
|
|
|
'email',
|
|
|
|
|
'password',
|
2026-01-17 13:46:20 +02:00
|
|
|
'notification_preferences',
|
2026-01-24 12:16:10 +02:00
|
|
|
'notification_channels',
|
|
|
|
|
'slack_webhook_url',
|
|
|
|
|
'telegram_chat_id',
|
|
|
|
|
'discord_webhook_url',
|
|
|
|
|
'teams_webhook_url',
|
|
|
|
|
'google_chat_webhook_url',
|
|
|
|
|
'webhook_url',
|
|
|
|
|
'sms_phone_number',
|
|
|
|
|
'opsgenie_api_key',
|
|
|
|
|
'pagerduty_integration_key',
|
2026-01-14 21:46:04 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The attributes that should be hidden for serialization.
|
|
|
|
|
*
|
|
|
|
|
* @var list<string>
|
|
|
|
|
*/
|
|
|
|
|
protected $hidden = [
|
|
|
|
|
'password',
|
|
|
|
|
'remember_token',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the attributes that should be cast.
|
|
|
|
|
*
|
|
|
|
|
* @return array<string, string>
|
|
|
|
|
*/
|
|
|
|
|
protected function casts(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'email_verified_at' => 'datetime',
|
|
|
|
|
'password' => 'hashed',
|
2026-01-17 13:46:20 +02:00
|
|
|
'notification_preferences' => 'array',
|
2026-01-24 12:16:10 +02:00
|
|
|
'notification_channels' => 'array',
|
2026-01-14 21:46:04 +02:00
|
|
|
];
|
|
|
|
|
}
|
2026-01-17 13:46:20 +02:00
|
|
|
|
2026-01-24 12:16:10 +02:00
|
|
|
/**
|
|
|
|
|
* Get enabled notification channels for a specific alert type
|
|
|
|
|
*/
|
|
|
|
|
public function getNotificationChannelsFor(string $alertType): array
|
|
|
|
|
{
|
|
|
|
|
$channels = $this->notification_channels ?? [];
|
|
|
|
|
return $channels[$alertType] ?? ['database'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Route notification for Slack
|
|
|
|
|
*/
|
|
|
|
|
public function routeNotificationForSlack(): ?string
|
|
|
|
|
{
|
|
|
|
|
return $this->slack_webhook_url;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Route notification for Telegram
|
|
|
|
|
*/
|
|
|
|
|
public function routeNotificationForTelegram(): ?string
|
|
|
|
|
{
|
|
|
|
|
return $this->telegram_chat_id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Route notification for Discord
|
|
|
|
|
*/
|
|
|
|
|
public function routeNotificationForDiscord(): ?string
|
|
|
|
|
{
|
|
|
|
|
return $this->discord_webhook_url;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-17 13:46:20 +02:00
|
|
|
public function sites(): HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Site::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function notifications(): HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Notification::class);
|
|
|
|
|
}
|
2026-01-14 21:46:04 +02:00
|
|
|
}
|