public function belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null)
{
if (is_null($relation)) {
list($current, $caller) = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
$relation = $caller['function'];
}
if (is_null($foreignKey)) {
$foreignKey = Str::snake($relation) . '_id';
}
$instance = new $related();
if ($instance instanceof Model) {
$instance->setConnection($this->getConnection()->getName());
} else {
$instance->setConnection($instance->getConnection()->getName());
}
$query = $instance->newQuery();
$otherKey = $otherKey ?: $instance->getKeyName();
return new BelongsTo($query, $this, $foreignKey, $otherKey, $relation);
}