Rubenwouters\CrmLauncher\ApiCalls\FetchTwitterContent::toggleFollowUser PHP Method

toggleFollowUser() public method

Follow/unfollow user
public toggleFollowUser ( object $contact, integer $twitterId ) : void | Illuminate\View\View
$contact object
$twitterId integer
return void | Illuminate\View\View
    public function toggleFollowUser($contact, $twitterId)
    {
        $client = initTwitter();
        try {
            if ($contact->following) {
                $contact->following = 0;
                $client->post('friendships/destroy.json?follow=true&user_id=' . $twitterId);
                Session::flash('flash_success', trans('crm-launcher::success.unfollow'));
            } else {
                $contact->following = 1;
                $client->post('friendships/create.json?follow=true&user_id=' . $twitterId);
                Session::flash('flash_success', trans('crm-launcher::success.follow'));
            }
            $contact->save();
        } catch (\GuzzleHttp\Exception\ClientException $e) {
            getErrorMessage($e->getResponse()->getStatusCode());
            return back();
        }
    }

Usage Example

 /**
  * Follow user on Twitter
  *
  * @param  integer $caseId
  *
  * @return \Illuminate\View\View
  */
 public function toggleFollowUser($caseId)
 {
     $case = $this->case->find($caseId);
     $contact = $case->contact;
     $twitterId = $contact->twitter_id;
     $this->twitterContent->toggleFollowUser($contact, $twitterId);
     return back();
 }