2026-03-19 19:25:51 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
|
|
|
|
|
class Project extends Model
|
|
|
|
|
{
|
|
|
|
|
use HasFactory, HasUlids;
|
|
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'name',
|
|
|
|
|
'platform',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected static function booted(): void
|
|
|
|
|
{
|
|
|
|
|
static::creating(function (Project $project) {
|
|
|
|
|
$project->dsn_public_key ??= Str::uuid()->toString();
|
|
|
|
|
$project->dsn_secret_key ??= Str::uuid()->toString();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getDsnAttribute(): string
|
|
|
|
|
{
|
|
|
|
|
$host = config('app.url');
|
|
|
|
|
|
|
|
|
|
return "{$host}/api/{$this->id}/store/?sentry_key={$this->dsn_public_key}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function users(): BelongsToMany
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(User::class)
|
|
|
|
|
->withPivot('role')
|
|
|
|
|
->withTimestamps();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function issues(): HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Issue::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function events(): HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(Event::class);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 19:47:06 +02:00
|
|
|
public function alertRules(): HasMany
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(AlertRule::class);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 19:25:51 +02:00
|
|
|
public function regenerateKeys(): void
|
|
|
|
|
{
|
|
|
|
|
$this->update([
|
|
|
|
|
'dsn_public_key' => Str::uuid()->toString(),
|
|
|
|
|
'dsn_secret_key' => Str::uuid()->toString(),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|