Browse Source

Update ProfileController

Daniel Supernault 7 years ago
parent
commit
e9627c4c4c

+ 10 - 2
app/Http/Controllers/ProfileController.php

@@ -61,15 +61,23 @@ class ProfileController extends Controller
     public function followers(Request $request, $username)
     {
       $profile = Profile::whereUsername($username)->firstOrFail();
+      // TODO: fix $profile/$user mismatch in profile & follower templates
+      $user = $profile;
+      $owner = Auth::check() && Auth::id() === $user->user_id;
+      $is_following = ($owner == false && Auth::check()) ? $user->followedBy(Auth::user()->profile) : false;
       $followers = $profile->followers()->orderBy('created_at','desc')->simplePaginate(12);
-      return view('profile.followers', compact('profile', 'followers'));
+      return view('profile.followers', compact('user', 'profile', 'followers', 'owner', 'is_following'));
     }
 
     public function following(Request $request, $username)
     {
       $profile = Profile::whereUsername($username)->firstOrFail();
+      // TODO: fix $profile/$user mismatch in profile & follower templates
+      $user = $profile;
+      $owner = Auth::check() && Auth::id() === $user->user_id;
+      $is_following = ($owner == false && Auth::check()) ? $user->followedBy(Auth::user()->profile) : false;
       $following = $profile->following()->orderBy('created_at','desc')->simplePaginate(12);
-      return view('profile.following', compact('profile', 'following'));
+      return view('profile.following', compact('user', 'profile', 'following', 'owner', 'is_following'));
     }
 
     public function savedBookmarks(Request $request, $username)

+ 2 - 2
resources/views/profile/partial/user-info.blade.php

@@ -14,7 +14,7 @@
             <span class="h5 pl-2 b-0">
             <a class="icon-settings text-muted" href="{{route('settings')}}"></a>
             </span>
-            @elseif ($following == true)
+            @elseif ($is_following == true)
             <span class="pl-4">
               <form class="follow-form" method="post" action="/i/follow" style="display: inline;" data-id="{{$user->id}}" data-action="unfollow">
                 @csrf
@@ -22,7 +22,7 @@
                 <button class="btn btn-outline-secondary font-weight-bold px-4 py-0" type="submit">Unfollow</button>
               </form>
             </span>
-            @elseif ($following == false)
+            @elseif ($is_following == false)
             <span class="pl-4">
               <form class="follow-form" method="post" action="/i/follow" style="display: inline;" data-id="{{$user->id}}" data-action="follow">
                 @csrf