1<?php
2
3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
4// See the LICENCE file in the repository root for full licence text.
5
6declare(strict_types=1);
7
8namespace App\Models;
9
10use Illuminate\Database\Eloquent\Relations\BelongsTo;
11
12class TeamMember extends Model
13{
14 public $incrementing = false;
15
16 protected $primaryKey = 'user_id';
17
18 public function team(): BelongsTo
19 {
20 return $this->belongsTo(Team::class);
21 }
22
23 public function user(): BelongsTo
24 {
25 return $this->belongsTo(User::class, 'user_id');
26 }
27
28 public function userOrDeleted(): User
29 {
30 $user = $this->user;
31
32 return $user === null || $user->isRestricted()
33 ? new DeletedUser(['user_id' => $this->user_id])
34 : $user;
35 }
36}