title: Bookmark an article in Laravel
body: <p>I am trying to create a functionality for a user to be able to bookmark and article and remove the article from his bookmarks as well. The functionality to bookmark an article works just fine, but when I try to remove the article from the bookmarks then it does not work and instead it inserts the same record but with the article_id being NULL.</p>
  
  <p>Here is my controller:</p>
  
  <pre><code>public function postBookmark() {
      $user_id    = Auth::user()-&gt;id;
      $article_id = Input::get('id');
      $bookmark   = Bookmark::where('user_id', '=', $user_id)-&gt;where('article_id', '=', $article_id);
      $article    = Article::where('id', '=', $article_id);
      $article    = $article-&gt;first();
  
      // I want to check if the article has been already bookmarked by the same user
      // but this if statement always returns true
      if(!empty($bookmark)) { 
          $bookmark = Bookmark::create(array(
               'user_id' =&gt; $user_id,
               'article_id' =&gt; $article_id,
           ));
  
          if($bookmark) {
              return View::make('article.view')
                 -&gt;with('article', $article)
                 -&gt;with('bookmarked', true);  
          }       
      } else {
          // Does not work
          $bookmark-&gt;delete();
  
          return View::make('article.view')
                 -&gt;with('article', $article)
                 -&gt;with('bookmarked', false);
      }
  
      return Redirect::route('article-all')
             -&gt;with('global', 'We were unable to bookmark the article. Please, try again later.');
  }
  </code></pre>
  
  <p>And here is part of my view:</p>
  
  <pre><code>{{ Form::open(array('action' =&gt; 'BookmarkController@postBookmark')) }}  
      &lt;input 
           type="checkbox" 
           name="id" 
           onClick="this.form.submit()"
           value="{{ $article-&gt;id }}" 
           id="bookmark" 
           {{ $bookmarked ? 'checked' : '' }}
      /&gt;
      &lt;label for="bookmark"&gt;Bookmark&lt;/label&gt;
  {{ Form::close() }}
  </code></pre>
  
  <p>I do also have a route with a post method for this functionality. I would highly appreciate if anyone could give any idea of why it does not work.</p>