Skip to content

Commit c0290ef

Browse files
Update the Livewire examples in the broadcasting docs (#66)
* Update broadcasting.md * Update broadcasting.md --------- Co-authored-by: Simon Hamp <[email protected]>
1 parent 5fce7af commit c0290ef

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

resources/views/docs/1/digging-deeper/broadcasting.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,44 @@ To make this process even easier when using [Livewire](https://livewire.laravel.
5757
listening to events. This is similar to
5858
[listening to Laravel Echo events using Livewire](https://livewire.laravel.com/docs/events#real-time-events-using-laravel-echo).
5959

60+
You may use a string name:
61+
62+
```php
63+
class AppSettings extends Component
64+
{
65+
public $windowFocused = true;
66+
67+
#[On('native:\\Native\\Laravel\\Events\\Windows\\WindowFocused')]
68+
public function windowFocused()
69+
{
70+
$this->windowFocused = true;
71+
}
72+
73+
#[On('native:\\Native\\Laravel\\Events\\Windows\\WindowBlurred')]
74+
public function windowBlurred()
75+
{
76+
$this->windowFocused = false;
77+
}
78+
}
79+
```
80+
81+
You may find it more convenient to use PHP's class name resolution keyword, `::class`:
82+
6083
```php
84+
use Native\Laravel\Events\Windows\WindowBlurred;
85+
use Native\Laravel\Events\Windows\WindowFocused;
86+
6187
class AppSettings extends Component
6288
{
6389
public $windowFocused = true;
6490

65-
#[On('native:\Native\Laravel\Events\Windows\WindowFocused')]
91+
#[On('native:'.WindowFocused::class)]
6692
public function windowFocused()
6793
{
6894
$this->windowFocused = true;
6995
}
7096

71-
#[On('native:\Native\Laravel\Events\Windows\WindowBlurred')]
97+
#[On('native:'.WindowBlurred::class)]
7298
public function windowBlurred()
7399
{
74100
$this->windowFocused = false;

0 commit comments

Comments
 (0)