title: How to use link table with Eloquent?
body: <p>In my Laravel 4 app, I have two models: Country and Grade wrote them as:</p>
  
  <p>Country.php:</p>
  
  <pre><code>class Country extends Eloquent {
      protected $fillable = [];
  
      public function grades()
      {
          return $this-&gt;hasMany('Grade', 'title');
      }
  }
  </code></pre>
  
  <p>Grade.php:</p>
  
  <pre><code>class Grade extends Eloquent {
      protected $fillable = [];
  
      public function country()
      {
  
          return $this-&gt;belongsTo('Country');
      }
  }
  </code></pre>
  
  <p>when I try to get all grades for specific country:</p>
  
  <pre><code>return Response::json(Country::find($country_id)-&gt;grades());
  </code></pre>
  
  <p>But this would result into empty object <code>{}</code></p>
  
  <p>I am using many to many link table:</p>
  
  <pre><code>Schema::create('countries_grades', function(Blueprint $table)
          {
              $table-&gt;increments('id');
              $table-&gt;integer('country_id');
              $table-&gt;integer('grade_id');
              $table-&gt;timestamps();
          });
  </code></pre>
  
  <p>It seems that laravel is not using the above table, what is the correct way to achieve this query?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Thanks for answers below! but I have found that no mater what I do, I will get empty object if I called graded as a method:</p>
  
  <pre><code>return Response::json(Country::find($country_id)-&gt;grades());
  </code></pre>
  
  <p>this should be:</p>
  
  <pre><code>return Response::json(Country::find($country_id)-&gt;grades);
  </code></pre>
  
  <p>otherwise, it woks well if I use <code>belongsToMany</code> for both <code>Grade</code> and <code>Country</code></p>
  
  <p>I hope this will help others!</p>