title: Find all posts associated with a tag in laravel
body: <p>I am building a blog with laravel where a post has many tags. I want to filter all post by a tag. means if I click on "PHP" tag I want to get all associated post.</p>
  
  <p><strong>Here is my code</strong></p>
  
  <p>I have two table first for tags and a second table for the link with posts</p>
  
  <p><strong>tag_table</strong></p>
  
  <pre><code> public function up()
  {
      Schema::create('tags', function (Blueprint $table) {
          $table-&gt;increments('id');
          $table-&gt;string('tags');
          $table-&gt;timestamps();
      });
  }
  </code></pre>
  
  <p><strong>relation tag table</strong></p>
  
  <pre><code>public function up()
  {
      Schema::create('article_tag', function (Blueprint $table) {
        $table-&gt;increments('id');
        $table-&gt;integer('article_id')-&gt;unsigned();
        $table-&gt;foreign('article_id')-&gt;references('id')-&gt;on('articles');
        $table-&gt;integer('tag_id')-&gt;unsigned();
        $table-&gt;foreign('tag_id')-&gt;references('id')-&gt;on('tags');
      });
  }
  </code></pre>
  
  <p><strong>Article Model</strong></p>
  
  <pre><code>class Article extends Model
  {
   public function tags()
   {
    return $this-&gt;belongsToMany('App\Tag');
   }
  } 
  </code></pre>
  
  <p><strong>tag model</strong></p>
  
  <pre><code>class Tag extends Model
  {
    public function articles()
   {
     return $this-&gt;belongsToMany('App\Article');
   }
  }
  </code></pre>
  
  <p><strong>Tag Controller</strong></p>
  
  <pre><code> public function show($id,$name)
  {
     //here I received tag id and name.
  
   $list-&gt;with('articles')-&gt;get();
   return view('articles.tagshow')-&gt;withList($list);
  
  }
  </code></pre>