belongsTo(User::class, 'owner_id'); } public function members(): BelongsToMany { return $this->belongsToMany(User::class)->withTimestamps(); } public function investigations(): BelongsToMany { return $this->belongsToMany(Investigation::class, 'investigation_group') ->withPivot('role') ->withTimestamps(); } public function isAccessibleBy(User $user): bool { return $this->owner_id === $user->id || $this->members()->where('users.id', $user->id)->exists(); } }