title: Get ids from related model laravel
body: <p>I have a many to many relationship set between two objects <code>Tag</code> and <code>Post</code>.
  Now, I have to check wich tags that post have in a checkbox list, like so:</p>
  
  <pre><code>//Load all possible tags in the controller
  //and send it to view
  $allTags = \App\Tag::all();
  return view('post.edit')-&gt;with('allTags');
  </code></pre>
  
  <p>In the view:</p>
  
  <pre><code>@foreach($allTags as $tag)
      &lt;input type="checkbox" name="tags[]" value="{{ $tag-&gt;id }}"/&gt;
      {{ $tag-&gt;description }}
  @endforeach
  </code></pre>
  
  <p>Now, when the user reloads the page, I have to check those checkboxes.</p>
  
  <p>My question is:</p>
  
  <p>This certainly work, but seems like <em>overkill</em> to me</p>
  
  <pre><code>$relatedTags = [];
  foreach($post-&gt;tags as $tag){
      $relatedTags[]= $tag-&gt;id;
  }
  </code></pre>
  
  <p>Is there a way to get only the ids without loading all those objects?</p>
  
  <p>Something like: <code>$relatedTags = $post-&gt;tags()-&gt;ids</code> ?</p>