From 586617d7fa1e076ea8088ab4a18eae7394a42814 Mon Sep 17 00:00:00 2001 From: Ghostie Date: Fri, 23 Aug 2024 15:42:43 -0500 Subject: [PATCH] showing following and followers --- app/Models/User.php | 10 +++++++--- resources/views/dashboard.blade.php | 10 ++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/Models/User.php b/app/Models/User.php index 7dfc5b3..e5dbb10 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -62,11 +62,15 @@ class User extends Authenticatable return $this->belongsToMany(User::class, "followers", "user_id", "follower_id"); } + // store the following + public function following() + { + return $this->belongsToMany(User::class, "followers", "follower_id", "user_id"); + } + // check if a user already follows another user - public function following(User $user) + public function is_following(User $user) { return $this->followers->contains($user->id); } - - // store the following } diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index 6b1adcc..e4a09dd 100644 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -31,12 +31,14 @@

- 0 - Followers + {{ $user->followers->count() }} + + @choice('follower|followers', $user->followers->count()) +

- 0 + {{ $user->following->count() }} Following

@@ -47,7 +49,7 @@ @auth @if ($user->id !== auth()->user()->id) - @if (!$user->following(auth()->user())) + @if (!$user->is_following(auth()->user()))
@csrf