public function belongsTo($related, $foreignKey = null)
{
list(, $caller) = debug_backtrace(false);
// If no foreign key was supplied, we can use a backtrace to guess the proper
// foreign key name by using the name of the relationship function, which
// when combined with an "_id" should conventionally match the columns.
$relation = $caller['function'];
if (is_null($foreignKey)) {
$foreignKey = snake_case($relation) . '_id';
}
// Once we have the foreign key names, we'll just create a new Eloquent query
// for the related models and returns the relationship instance which will
// actually be responsible for retrieving and hydrating every relations.
$instance = new $related();
$query = $instance->newQuery();
return new BelongsTo($query, $this, $foreignKey, $relation);
}