diff --git a/app/Livewire/UserStack.php b/app/Livewire/UserStack.php index 2f0ea0c..e0b8b46 100644 --- a/app/Livewire/UserStack.php +++ b/app/Livewire/UserStack.php @@ -2,6 +2,7 @@ namespace App\Livewire; +use Illuminate\Support\Facades\Auth; use Livewire\Component; class UserStack extends Component @@ -12,8 +13,20 @@ class UserStack extends Component public int $limit = 5; + public bool $viewAll = false; + public function render() { return view('livewire.user-stack'); } + + public function toggleViewAll() + { + $this->viewAll = ! $this->viewAll; + } + + public function followUser($user) + { + $user->followers->syncWithoutDetaching(Auth::id()); + } } diff --git a/app/Models/User.php b/app/Models/User.php index f8f22c9..a48cd1a 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -66,6 +66,24 @@ class User extends Authenticatable implements MustVerifyEmail return $this->belongsToMany(User::class, 'user_follows', 'following_id', 'follower_id'); } + public function isFollowing(User|int $user): bool + { + $userId = $user instanceof User ? $user->id : $user; + return $this->following()->where('following_id', $userId)->exists(); + } + + public function follow(User|int $user): void + { + $userId = $user instanceof User ? $user->id : $user; + $this->following()->syncWithoutDetaching($userId); + } + + public function unfollow(User|int $user): void + { + $userId = $user instanceof User ? $user->id : $user; + $this->following()->detach($userId); + } + /** * The data that is searchable by Scout. */ diff --git a/resources/views/livewire/user-stack.blade.php b/resources/views/livewire/user-stack.blade.php index 5796e44..0bff890 100644 --- a/resources/views/livewire/user-stack.blade.php +++ b/resources/views/livewire/user-stack.blade.php @@ -2,22 +2,26 @@
no u
+{{__("Member Since")}} {{ $user->created_at->format("M d, h:m a") }}