public function retrieve()
 {
     $twitterPosts = SocialPost::join('user_social_post', 'social_post.id', '=', 'user_social_post.social_post_id')->where('user_social_post.user_id', '=', $this->userId)->where('social_post.type', '=', 'twitter')->select('social_post.*')->get();
     $maxId = 0;
     foreach ($twitterPosts as $post) {
         $postJSON = json_decode($post->post);
         $maxId = $postJSON->id > $maxId ? $postJSON->id : $maxId;
     }
     return $maxId;
 }
 private function checkPostInDB($postId, $userId)
 {
     $instagramPostsFromUser = SocialPost::join('user_social_post', 'social_post.id', '=', 'user_social_post.social_post_id')->where('user_social_post.user_id', '=', $userId)->where('social_post.type', '=', 'instagram')->get();
     foreach ($instagramPostsFromUser as $instagramPost) {
         $post = json_decode($instagramPost->post);
         if ($post->id === $postId) {
             return true;
         }
     }
     return false;
 }
 public function assign()
 {
     DB::transaction(function () {
         $postCreatedTimestamp = strtotime($this->post['created_time']);
         $postCreatedTime = Carbon::createFromTimestamp($postCreatedTimestamp);
         //Save the post
         $socialPost = new SocialPost();
         $socialPost->type = 'facebook';
         $socialPost->post = json_encode($this->post);
         $socialPost->created_at = $postCreatedTime;
         $socialPost->save();
         //Assign social post to the user
         $userSocialPost = new UserSocialPost();
         $userSocialPost->user_id = $this->userId;
         $userSocialPost->social_post_id = $socialPost->id;
         $userSocialPost->created_at = $postCreatedTime;
         $userSocialPost->save();
     });
     return true;
 }
 public function retrieve()
 {
     return 0;
     $instagramPosts = SocialPost::join('user_social_post', 'user_social_post.social_post_id', '=', 'social_post.id')->where('social_post.type', '=', 'instagram')->where('user_social_post.user_id', '=', $this->userId)->get();
 }