/**
  * Store a relation between 2 contributors.
  *
  * @param  \Illuminate\Http\Request $request
  * @return \Illuminate\Http\Response
  */
 public function follow(Request $request)
 {
     $contributor_id = $request->input('contributor_id');
     $following_id = $request->input('following_id');
     if ($contributor_id == $following_id) {
         return response()->json(['request_id' => uniqid(), 'status' => 'denied', 'message' => 'You cannot follow yourself', 'timestamp' => Carbon::now()], 400);
     }
     $isFollowing = Follower::whereContributorId($contributor_id)->whereFollowing($following_id)->count();
     if (!$isFollowing) {
         $follower = new Follower();
         $follower->contributor_id = $contributor_id;
         $follower->following = $following_id;
         if ($follower->save()) {
             $contributor = Contributor::findOrFail($contributor_id);
             $following = Contributor::findOrFail($following_id);
             Activity::create(['contributor_id' => $contributor_id, 'activity' => Activity::followActivity($contributor->username, $following->username)]);
             if ($following->email_follow) {
                 $follower->sendEmailNotification($contributor, $following);
             }
             return response()->json(['request_id' => uniqid(), 'status' => 'success', 'message' => $contributor->name . ' now is following ' . $following->name, 'timestamp' => Carbon::now()]);
         }
         return response()->json(['request_id' => uniqid(), 'status' => 'failure', 'message' => Lang::get('alert.database.generic'), 'timestamp' => Carbon::now()], 500);
     }
     return response()->json(['request_id' => uniqid(), 'status' => 'denied', 'message' => 'You already follow this contributor', 'timestamp' => Carbon::now()], 400);
 }
 /**
  * Store a relation between 2 contributors.
  *
  * @param  \Illuminate\Http\Request $request
  * @return \Illuminate\Http\Response
  */
 public function follow(Request $request)
 {
     /*
      * --------------------------------------------------------------------------
      * Perform follow request
      * --------------------------------------------------------------------------
      * This operation only for authenticate user, a contributor follow another
      * contributor, populate the data and make sure there is no record following
      * from contributor A to B before then perform insert data.
      */
     if (Auth::check() && $request->ajax()) {
         $contributor_id = Auth::user()->id;
         $following_id = $request->input('id');
         $isFollowing = Follower::whereContributorId($contributor_id)->whereFollowing($following_id)->count();
         if (!$isFollowing) {
             $follower = new Follower();
             $follower->contributor_id = $contributor_id;
             $follower->following = $following_id;
             if ($follower->save()) {
                 $following = Contributor::findOrFail($following_id);
                 /*
                  * --------------------------------------------------------------------------
                  * Create following activity
                  * --------------------------------------------------------------------------
                  * Create new instance of Activity and insert following activity.
                  */
                 Activity::create(['contributor_id' => $contributor_id, 'activity' => Activity::followActivity(Auth::user()->username, $following->username)]);
                 if ($following->email_follow) {
                     $follower->sendEmailNotification(Auth::user(), $following);
                 }
                 return response('success');
             }
             return response('failed', 500);
         }
         return response('success');
     } else {
         return response('restrict', 401);
     }
 }