title: Eloquent Relationship
body: <p>Why am I getting this error for such a simple relationship query?</p>
  
  <pre><code>Call to undefined method Illuminate\Database\Query\Builder::country()
  </code></pre>
  
  <p>I just want to get a list of lookup values from my lookup table called <code>pc_country</code>. I have even included the namespaces!</p>
  
  <p>Controller;</p>
  
  <pre><code>$tableName = $postcode_tablename-&gt;dataset; //eg 201502_postcode
  
  $country = PostcodeExtract::fromTable($tableName)
                          -&gt;country() //this is generating the error!
                          -&gt;distinct()
                          -&gt;select('description')
                          -&gt;get();
  
  var_dump($country);
  exit;
  </code></pre>
  
  <p>Country Model;</p>
  
  <pre><code>&lt;?php namespace App\Models;
  
  use Illuminate\Database\Eloquent\Model;
  
  class Country extends Model {
  
    protected $connection = 'postcodes';
  
    public $table = 'pc_country';
  
    protected $fillable = ['description', 'country_id', 'code'];
  
    public function postcodeExtract()
    {
      return $this-&gt;hasMany('App\Models\PostcodeExtract');
    }
  }
  </code></pre>
  
  <p>PostCode Extract Model;</p>
  
  <pre><code>&lt;?php namespace App\Models;
  
  use Illuminate\Database\Eloquent\Model;
  
  class PostcodeExtract extends Model {
  
  protected $connection = 'postcodes';
  
  protected $fillable = ['country'];
  
    public function scopeFromTable($query, $tableName) 
    {
      return $query-&gt;from($tableName);
    }
  
    public function country()
    {
      return $this-&gt;belongsTo('App\Model\Country');
    }
  }
  </code></pre>
  
  <p>My <code>201502_postcode</code> table has a <code>country_id</code> and my <code>pc_country</code> table has a <code>id</code> field for it to do the lookup on. Is that correct? I don't see the problem...</p>