public function hasMany($related, $foreignKey = null, $localKey = null)
{
$foreignKey = $foreignKey ?: $this->getForeignKey();
$instance = new $related();
if ($instance instanceof Model) {
$instance->setConnection($this->getConnection()->getName());
} else {
$instance->setConnection($instance->getConnection()->getName());
}
$localKey = $localKey ?: $this->getKeyName();
return new HasMany($instance->newQuery(), $this, $foreignKey, $localKey);
}