1 | <?php |
||
2 | |||
3 | namespace App\Events; |
||
4 | |||
5 | use Illuminate\Broadcasting\InteractsWithSockets; |
||
6 | use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow; |
||
7 | use Illuminate\Foundation\Events\Dispatchable; |
||
8 | use Illuminate\Queue\SerializesModels; |
||
9 | use Illuminate\Support\Facades\Auth; |
||
10 | use MallardDuck\DynamicEcho\Channels\{ |
||
11 | BaseDynamicChannelFormula, |
||
12 | PrivateUserChannelParameters, |
||
13 | }; |
||
14 | use MallardDuck\DynamicEcho\Contracts\{ |
||
15 | HasDynamicChannelFormula, |
||
16 | ImplementsDynamicEcho, |
||
17 | }; |
||
18 | |||
19 | class ConsoleLogEvent implements ShouldBroadcastNow, ImplementsDynamicEcho, HasDynamicChannelFormula |
||
20 | { |
||
21 | use Dispatchable; |
||
22 | use InteractsWithSockets; |
||
23 | use BaseDynamicChannelFormula; |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
24 | |||
25 | public int $userId; |
||
26 | |||
27 | /** |
||
28 | * A message text string for the console log notification. |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | public string $message; |
||
33 | |||
34 | public function __construct(string $message) |
||
35 | { |
||
36 | /** @var App\Models\User $user */ |
||
37 | $user = Auth::user(); |
||
38 | $this->userId = $user->id; |
||
39 | $this->message = $message; |
||
40 | } |
||
41 | |||
42 | public static function getChannelParametersClassname(): string |
||
43 | { |
||
44 | return PrivateUserChannelParameters::class; |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * Get the JS callback for this event. |
||
49 | * |
||
50 | * In this case, we're just shoving a message into console.log. |
||
51 | * |
||
52 | * @return string |
||
53 | */ |
||
54 | public static function getEventJSCallback(): string |
||
55 | { |
||
56 | return <<<JSCALLBACK |
||
57 | (e) => { |
||
58 | console.log(e.message); |
||
59 | } |
||
60 | JSCALLBACK; |
||
61 | } |
||
62 | } |
||
63 |