61 lines
1.4 KiB
PHP
61 lines
1.4 KiB
PHP
<?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);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function regenerateKeys(): void
|
||
|
|
{
|
||
|
|
$this->update([
|
||
|
|
'dsn_public_key' => Str::uuid()->toString(),
|
||
|
|
'dsn_secret_key' => Str::uuid()->toString(),
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
}
|