5 use App\Events\ProtocolAdded;
6 use Illuminate\Database\Eloquent\Factories\HasFactory;
7 use Illuminate\Database\Eloquent\Model;
9 class Protocol extends Model
13 public static function resultReported(Tournament $tournament, Result $result, User $user) {
14 $protocol = static::create([
15 'tournament_id' => $tournament->id,
16 'user_id' => $user->id,
17 'type' => 'result.report',
19 'tournament' => static::tournamentMemo($tournament),
20 'result' => static::resultMemo($result),
23 ProtocolAdded::dispatch($protocol);
26 public static function roundAdded(Tournament $tournament, Round $round, User $user) {
27 $protocol = static::create([
28 'tournament_id' => $tournament->id,
29 'user_id' => $user->id,
30 'type' => 'round.create',
32 'tournament' => static::tournamentMemo($tournament),
33 'round' => static::roundMemo($round),
36 ProtocolAdded::dispatch($protocol);
39 public static function tournamentCreated(Tournament $tournament, User $user) {
40 $protocol = static::create([
41 'tournament_id' => $tournament->id,
42 'user_id' => $user->id,
43 'type' => 'tournament.create',
45 'tournament' => static::tournamentMemo($tournament),
48 ProtocolAdded::dispatch($protocol);
52 protected static function resultMemo(Result $result) {
55 'time' => $result->time,
59 protected static function roundMemo(Round $round) {
62 'seed' => $round->seed,
66 protected static function tournamentMemo(Tournament $tournament) {
68 'id' => $tournament->id,
69 'title' => $tournament->title,
73 protected static function userMemo(User $user) {
76 'username' => $user->username,
77 'discriminator' => $user->discriminator,
78 'avatar' => $user->avatar,
83 public function tournament() {
84 return $this->belongsTo(Tournament::class);
87 public function user() {
88 return $this->belongsTo(User::class);
96 protected $fillable = [