forge/app/Livewire/User/FollowButtons.php
Refringe 691f352d01
User Follow Components
Updates the user follow component to two smaller components. Still needs to be optimized.
2024-09-24 00:40:33 -04:00

53 lines
1.0 KiB
PHP

<?php
namespace App\Livewire\User;
use Illuminate\View\View;
use Livewire\Attributes\Locked;
use Livewire\Component;
class FollowButtons extends Component
{
/**
* The ID of the user whose profile is being viewed.
*/
#[Locked]
public int $profileUserId;
/**
* Whether the authenticated user is currently following the profile user.
*/
#[Locked]
public bool $isFollowing;
/**
* Action to follow a user.
*/
public function follow(): void
{
auth()->user()->follow($this->profileUserId);
$this->isFollowing = true;
$this->dispatch('user-follow-change');
}
/**
* Action to unfollow a user.
*/
public function unfollow(): void
{
auth()->user()->unfollow($this->profileUserId);
$this->isFollowing = false;
$this->dispatch('user-follow-change');
}
/**
* Render the component.
*/
public function render(): View
{
return view('livewire.user.follow-buttons');
}
}