I have the list of users, that each of them is has a followers count.
This is list component of the users.
class Index extends Component
{
public Collection $users;
public function render(): View
{
return view('livewire.users.index', [
'users' => $this->users,
]);
}
}
Then this is the item of each the list.
class Item extends Component
{
public User $user;
public function render(): View
{
return view('livewire.users.item', [
'users' => $this->user,
]);
}
}
And then this is the followers component that should be reactive, but it doesnt.
class Follower extends Component
{
#[Reactive]
public int $count;
public function render(): string
{
return <<<'BLADE'
<div class="p-2 flex items-center flex-col">
<strong class="font-bold">{{ $count }}</strong>
<div>
followers
</div>
</div>
BLADE;
}
}
The follow button is just simple.
class FollowButton extends Component
{
public User $user;
public function follow(): void
{
Auth::user()->toggleFollow($this->user);
}
public function render(): string
{
return <<<'BLADE'
<div>
<x-primary-button wire:click="follow">
{{ Auth::user()->isFollowing($user) ? 'Unfollow' : 'Follow' }}
</x-primary-button>
</div>
BLADE;
}
}