/** * Pending function for with(), joining other tables to current */ protected function withPending() { $joins = $this->pending['with']; foreach ($joins as $join) { $local = count($join) > 1 ? array_slice($join, -2, 1)[0] : $this->name; $foreign = end($join); $relation = Relation::table($local)->with($foreign); $data = $this->data; foreach ($join as $part) { $data = $relation->build($data, $part); } } }