title: BadMethodCallException with message 'Call to undefined method Illuminate\Database\Query\Builder::belongToMany()'
body: <p>Following the instructions in this laracast :</p>
  
  <p><a href="https://laracasts.com/series/laravel-5-fundamentals/episodes/21" rel="nofollow">https://laracasts.com/series/laravel-5-fundamentals/episodes/21</a></p>
  
  <p>I created a Channel model </p>
  
  <pre><code>class Channel extends Model
  {
      //
      protected $fillable = [
          'title',
          'description',
          'published_at',
  
      ];
  
      public function scopePublished($query) {
          $query-&gt;where('published_at', '&lt;=', Carbon::now());
      }
  
      public function setPublishedAtAttribute($date) {
          $this-&gt;attributes['published_at'] = Carbon::createFromFormat('Y-m-d', $date);   
      }
      /*
      * Get the tags associated with the given Channel
      *
      */
      public function tags() {
          return $this-&gt;belongsToMany('App\Tag'); //tag_id
      }
  }
  </code></pre>
  
  <p>and a Tag model </p>
  
  <pre><code>class Tag extends Model
  {
      //
      protected $fillable = [
          'name', 'description',
      ];
      /**
      * Get the channels associated with the given tag
      */
      public function channels() {
          return $this-&gt;belongToMany('App\Channel'); //channel_id
      }
  }
  </code></pre>
  
  <p>so there's a many-to-many relation betweeen Channel and Tag through the pivot table. </p>
  
  <p>My migrations look as follows</p>
  
  <pre><code>use Illuminate\Database\Schema\Blueprint;
  use Illuminate\Database\Migrations\Migration;
  
  class CreateChannelsTable extends Migration
  {
      /**
       * Run the migrations.
       *
       * @return void
       */
      public function up()
      {
          Schema::create('channels', function (Blueprint $table) {
              $table-&gt;increments('id');
              $table-&gt;string('title');
              $table-&gt;text('description');
              $table-&gt;text('url');
              $table-&gt;text('channelposter');
              $table-&gt;timestamp('published_at');
              $table-&gt;timestamps();
          });
      }
  
      /**
       * Reverse the migrations.
       *
       * @return void
       */
      public function down()
      {
          Schema::drop('channels');
      }
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>use Illuminate\Database\Schema\Blueprint;
  use Illuminate\Database\Migrations\Migration;
  
  class CreateTagsTable extends Migration
  {
      /**
       * Run the migrations.
       *
       * @return void
       */
      public function up()
      {
          Schema::create('tags', function (Blueprint $table) {
              $table-&gt;increments('id');
              $table-&gt;string('name');
              $table-&gt;string('description');
              $table-&gt;timestamps();
  
          });
          //channel_tag
          Schema::create('channel_tag', function(Blueprint $table) {
              $table-&gt;integer('channel_id')-&gt;unsigned()-&gt;index();
              $table-&gt;foreign('channel_id')-&gt;references('id')-&gt;on('channels')-&gt;onDelete('cascade');
  
              $table-&gt;integer('tag_id')-&gt;unsigned()-&gt;index();
              $table-&gt;foreign('tag_id')-&gt;references('id')-&gt;on('tags')-&gt;onDelete('cascade');
              $table-&gt;timestamps();
          });
  
  
  
      }
  
      /**
       * Reverse the migrations.
       *
       * @return void
       */
      public function down()
      {
          Schema::drop('tags');
          Schema::drop('channel_tag');
      }
  }
  </code></pre>
  
  <p>However, when I use artisan tinker to connect a channel to a tag as follows :</p>
  
  <pre><code>==&gt; php artisan  tinker
  Psy Shell v0.6.1 (PHP 5.6.16 — cli) by Justin Hileman
  &gt;&gt;&gt; $channel=App\Channel::first();
  =&gt; App\Channel {#660
       id: 1,
       title: "Test1",
       description: "Test1",
       url: "",
       channelposter: "",
       published_at: "2016-01-06 02:54:20",
       created_at: "2016-01-06 02:54:20",
       updated_at: "2016-01-06 02:54:20",
     }
  &gt;&gt;&gt; $tag = new App\Tag;
  =&gt; App\Tag {#649}
  &gt;&gt;&gt; $tag-&gt;name = "Recommended";
  =&gt; "Recommended"
  &gt;&gt;&gt; $tag-&gt;description = "Recommended";
  =&gt; "Recommended"
  &gt;&gt;&gt; $tag-&gt;save();
  =&gt; true
  &gt;&gt;&gt; DB::select('SELECT * FROM channel_tag');
  =&gt; []
  &gt;&gt;&gt; $channel-&gt;tags()-&gt;attach(1);
  =&gt; null
  &gt;&gt;&gt; DB::select('SELECT * FROM channel_tag');
  =&gt; [
       {#658
         +"channel_id": 1,
         +"tag_id": 1,
         +"created_at": "2016-01-05 21:56:46",
         +"updated_at": "0000-00-00 00:00:00",
       },
     ]
  &gt;&gt;&gt; $tag-&gt;channels-&gt;toArray();
  BadMethodCallException with message 'Call to undefined method Illuminate\Database\Query\Builder::belongToMany()'
  </code></pre>
  
  <p>This is not making sense and it feels like it might be a bug but I'm not sure. I'm using Laravel Framework version 5.2.6 and PHP 5.6.16 </p>