Laravel 5 | Many to Many Relationship not working
<p>I'm new in laravel5.
I use "Many to Many" Relationships to get all messages based on the given tag.</p>

<p>MESSAGE MODEL : </p>

<pre><code>   function tags(){
      return $this-&gt;belongsToMany('App\tags')-&gt;withTimestamps();
    }
</code></pre>

<p>TAGS MODEL :</p>

<pre><code>  public function messages() {
     return $this-&gt;belongsToMany('App\messages', "messages_tags",     "messages_id", "tags_id");
  }
</code></pre>

<p>MY INPUT :</p>

<pre><code>   $tag = App\tags::where('name','public')-&gt;first();
</code></pre>

<p>($tag :)</p>

<pre><code> App\tags {#681
 id: "5",
 name: "Public",
 created_at: "2016-02-10 13:51:36",
 updated_at: "2016-02-10 08:21:36",
 }
</code></pre>

<p>I tried to get Messages with Tag.</p>

<pre><code> $tag-&gt;messages()-&gt;get();
</code></pre>

<p>MY OUTPUT :</p>

<pre><code> []
</code></pre>

<p>But i have messages with the Tag "Public".</p>

<p>What is Wrong with my code ?</p>