protected function makeRelation($model, $name, $data)
    {
        // The data must be an array and must contain arrays
        if (!is_array($data)
            || empty($data)
            || count(array_filter($data, function ($child) {
                return !is_array($child);
            }))) {
            return false;
        }

        // The input name should be a function defined on the model.
        if (!method_exists($model, $name)) {
            return false;
        }

        // Check if the running the function actually returns a relationship
        $relation = $model->$name();
        if (!is_a($relation, Relation::class)) {
            return false;
        }

        // Return the relationship object
        return $relation;
    }