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 @@

{{$label}}

-
+
@foreach($users->slice(0, $limit) as $user)
- + {{$user->name[0]}} -
+
{{$user->name}}
@endforeach @if($users->count() > $limit)
- +{{$users->count()-$limit}} -
+ +{{$users->count()-$limit}} +
{{$users->count()}} total
@@ -25,20 +29,38 @@
@if($users->count() > $limit)
- +
@endif -

testing

+

{{$user->name}}'s {{$label}}

-

no u

+
+ @foreach($users as $user) + {{-- user tile --}} +
+ {{$user->name}} +
+ {{$user->name}} + {{__("Member Since")}} {{ $user->created_at->format("M d, h:m a") }} +
+ +
+ @endforeach +
- + {{__('Close')}} diff --git a/resources/views/user/show.blade.php b/resources/views/user/show.blade.php index 4df26d4..8233df5 100644 --- a/resources/views/user/show.blade.php +++ b/resources/views/user/show.blade.php @@ -17,20 +17,35 @@

{{__("Member Since")}} {{ $user->created_at->format("M d, h:m a") }}

- @if(\Illuminate\Support\Facades\Auth::check()) - @if(\Illuminate\Support\Facades\Auth::id() != $user->id) -
- -
+ @if(auth()->check()) + @if(auth()->id() != $user->id) + @if(auth()->user()->isFollowing($user)) +
+ +
+ @else +
+ +
+ @endif @endif