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 roundAdded(Tournament $tournament, Round $round, User $user) {
14 $protocol = static::create([
15 'tournament_id' => $tournament->id,
16 'user_id' => $user->id,
17 'type' => 'round.create',
19 'tournament' => static::tournamentMemo($tournament),
20 'round' => static::roundMemo($round),
23 ProtocolAdded::dispatch($protocol);
26 public static function tournamentCreated(Tournament $tournament, User $user) {
27 $protocol = static::create([
28 'tournament_id' => $tournament->id,
29 'user_id' => $user->id,
30 'type' => 'tournament.create',
32 'tournament' => static::tournamentMemo($tournament),
35 ProtocolAdded::dispatch($protocol);
39 protected static function roundMemo(Round $round) {
42 'seed' => $round->seed,
46 protected static function tournamentMemo(Tournament $tournament) {
48 'id' => $tournament->id,
49 'title' => $tournament->title,
53 protected static function userMemo(User $user) {
56 'username' => $user->username,
57 'discriminator' => $user->discriminator,
58 'avatar' => $user->avatar,
63 public function tournament() {
64 return $this->belongsTo(Tournament::class);
67 public function user() {
68 return $this->belongsTo(User::class);
76 protected $fillable = [