Skip to content

Commit

Permalink
User can follow and unfollow
Browse files Browse the repository at this point in the history
  • Loading branch information
itxshakil committed Jun 16, 2020
1 parent 1ef7fd9 commit 2fcf4b2
Show file tree
Hide file tree
Showing 7 changed files with 323 additions and 76 deletions.
14 changes: 14 additions & 0 deletions app/Http/Controllers/FollowController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App\Http\Controllers;

use App\User;
use Illuminate\Http\Request;

class FollowController extends Controller
{
public function store(User $user)
{
return $user->profile->follower()->toggle(auth()->id());
}
}
4 changes: 3 additions & 1 deletion app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public function show(User $user)
{
$profile = $user->profile->load('user')->loadCount('follower');

return view('profiles.show', compact('profile'));
$isFollowing = (auth()->user()) ? $profile->follower->contains(auth()->id()) : false;

return view('profiles.show', compact('profile', 'isFollowing'));
}

/**
Expand Down
Loading

0 comments on commit 2fcf4b2

Please sign in to comment.