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 alertRules(): HasMany { return $this->hasMany(AlertRule::class); } public function invitations(): HasMany { return $this->hasMany(ProjectInvitation::class); } public function regenerateKeys(): void { $this->update([ 'dsn_public_key' => Str::uuid()->toString(), 'dsn_secret_key' => Str::uuid()->toString(), ]); } public function userRole(User $user): ?string { return $this->users() ->where('users.id', $user->id) ->first() ?->pivot ?->role; } public function hasOwner(User $user): bool { return $this->userRole($user) === 'owner'; } public function hasAdmin(User $user): bool { return in_array($this->userRole($user), ['owner', 'admin']); } }