/** * Pending function for with(), joining other tables to current */ protected function withPending() { $joins = $this->pending['with']; foreach ($joins as $join) { if (count($join) > 1) { $local = array_slice($join, -2, 1); $local = $local[0]; } else { $local = $this->_name; } // $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); } } }