File tree Expand file tree Collapse file tree 2 files changed +25
-33
lines changed Expand file tree Collapse file tree 2 files changed +25
-33
lines changed Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
- use Livewire\Volt\ Component ;
4
- use Livewire\Attributes\ On ;
3
+ declare (strict_types = 1 );
5
4
6
- new class extends Component {
5
+ use function Livewire\Volt\ {on };
6
+ use Illuminate\Support\Facades\ Auth ;
7
7
8
- public function with (): array
9
- {
10
- return [
11
- ' count' => \Illuminate \Support \Facades \Auth:: user ()-> unreadNotifications ()-> count (),
12
- ];
13
- }
8
+ use function Livewire\Volt\ {state };
14
9
15
- # [On('NotificationMarkedAsRead')]
16
- public function updateCount (int $count ): int
17
- {
18
- return $count ;
19
- }
20
- } ? >
10
+ state ([' count' => Auth:: user ()-> unreadNotifications ()-> count ()]);
11
+
12
+ on ([' NotificationMarkedAsRead' => function (int $count ) {
13
+ return $count ;
14
+ }]);
15
+
16
+ ? >
21
17
22
18
<span class =" rounded-full bg-green-100 px-3 text-base text-green-500" >
23
19
{{ $count } }
Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
- use Livewire\Volt\ Component ;
4
- use Livewire\Attributes\ On ;
3
+ declare (strict_types = 1 );
4
+
5
+ use function Livewire\Volt\ {on };
5
6
use Illuminate\Support\Facades\ Auth ;
6
7
7
- new class extends Component {
8
+ use function Livewire\Volt\ {state };
9
+
10
+ state ([' hasNotification' => Auth:: user ()-> unreadNotifications ()-> count () > 0 ]);
8
11
9
- public function with (): array
10
- {
11
- return [
12
- ' hasNotification' => $this -> setHasNotification (
13
- Auth:: user ()-> unreadNotifications ()-> count (), // @phpstan-ignore-line
14
- ),
15
- ];
16
- }
12
+ on ([' NotificationMarkedAsRead' => function (int $count ) {
13
+ return $count > 0 ;
14
+ }]);
17
15
18
- # [On('NotificationMarkedAsRead')]
19
- public function setHasNotification (int $count ): bool
20
- {
21
- return $count > 0 ;
22
- }
23
- } ? >
16
+ ? >
24
17
25
18
<span
26
- class =" {{ $hasNotification ? ' shadow-solid absolute right-0 top-0 block size-2 rounded-full bg-primary-600 text-white' : ' hidden' } }"
19
+ @class ([
20
+ ' hidden' => ! $hasNotification ,
21
+ ' shadow-solid absolute right-0 top-0 block size-2 rounded-full bg-primary-600 text-white' => $hasNotification
22
+ ] )
27
23
></span >
You can’t perform that action at this time.
0 commit comments