showing following and followers
This commit is contained in:
parent
f12ac2489a
commit
586617d7fa
@ -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
|
||||
}
|
||||
|
@ -31,12 +31,14 @@
|
||||
</div>
|
||||
|
||||
<p class="text-gray-800 text-sm mb-3 font-bold mt-5">
|
||||
0
|
||||
<span class="font-normal">Followers</span>
|
||||
{{ $user->followers->count() }}
|
||||
<span class="font-normal">
|
||||
@choice('follower|followers', $user->followers->count())
|
||||
</span>
|
||||
</p>
|
||||
|
||||
<p class="text-gray-800 text-sm mb-3 font-bold">
|
||||
0
|
||||
{{ $user->following->count() }}
|
||||
<span class="font-normal">Following</span>
|
||||
</p>
|
||||
|
||||
@ -47,7 +49,7 @@
|
||||
|
||||
@auth
|
||||
@if ($user->id !== auth()->user()->id)
|
||||
@if (!$user->following(auth()->user()))
|
||||
@if (!$user->is_following(auth()->user()))
|
||||
<form action="{{ route('users.follow', $user) }}" method="POST">
|
||||
@csrf
|
||||
<input type="submit"
|
||||
|
Loading…
x
Reference in New Issue
Block a user