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
6namespace App\Events;
7
8use DB;
9use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
10
11abstract class BroadcastableEventBase implements ShouldBroadcast
12{
13 /**
14 * Broadcasts the event.
15 *
16 * @param bool $afterCommit true to broadcast after the current connection's transaction is committed, false to queue immediately.
17 * @return void
18 */
19 public function broadcast(bool $afterCommit = false)
20 {
21 if ($afterCommit) {
22 DB::afterCommit(fn () => event($this));
23 } else {
24 event($this);
25 }
26 }
27}