Illuminate\Database\Eloquent\Builder::parseWithRelations PHP Method

parseWithRelations() protected method

Parse a list of relations into individuals.
protected parseWithRelations ( array $relations ) : array
$relations array
return array
    protected function parseWithRelations(array $relations)
    {
        $results = [];
        foreach ($relations as $name => $constraints) {
            // If the "relation" value is actually a numeric key, we can assume that no
            // constraints have been specified for the eager load and we'll just put
            // an empty Closure with the loader so that we can treat all the same.
            if (is_numeric($name)) {
                if (Str::contains($constraints, ':')) {
                    list($constraints, $columns) = explode(':', $constraints);
                    $f = function ($q) use($columns) {
                        $q->select(explode(',', $columns));
                    };
                } else {
                    $f = function () {
                        //
                    };
                }
                list($name, $constraints) = [$constraints, $f];
            }
            // We need to separate out any nested includes. Which allows the developers
            // to load deep relationships using "dots" without stating each level of
            // the relationship with its own key in the array of eager load names.
            $results = $this->parseNestedWith($name, $results);
            $results[$name] = $constraints;
        }
        return $results;
    }