Example #1
0
 public function getRemoveFeed(Request $request, $feed_id)
 {
     $user_id = \Auth::user()->id;
     #Remove this Feed from the User_Feed Table if it exists
     $userFeed = \p4\UserFeed::where('feed_id', '=', $feed_id)->where('user_id', '=', $user_id)->first();
     if ($userFeed) {
         $userFeed->delete();
     }
     # Remove any Articles Marked for Deletion
     $articles = \p4\Article::where('feed_id', $feed_id)->pluck('id');
     $userFeedArticles = \p4\UserArticle::wherein('article_id', $articles)->where('user_id', '=', $user_id);
     if ($userFeedArticles) {
         $userFeedArticles->delete();
     }
     #Remove this Feed from the Feeds table if nobody else is subscribed to it
     if (!\p4\UserFeed::where('feed_id', '=', $feed_id)->exists()) {
         #Remove Articles First
         \p4\Article::where('feed_id', '=', $feed_id)->delete();
         #Now Remove the Feed
         $feed = \p4\Feed::where('id', '=', $feed_id)->first();
         if ($feed) {
             $feed->delete();
         }
     }
     # Update the Session Feeds so the updated list will appear in the left nav
     \p4\User::setSessionFeeds($user_id);
     return \Redirect::to('/Manage');
 }