We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 11bc91d commit 1714347Copy full SHA for 1714347
src/NestableCollection.php
@@ -202,4 +202,26 @@ public function getTotal()
202
{
203
return $this->total();
204
}
205
+
206
+ /**
207
+ * Sets the $item->parent relation for each item in the NestableCollection to be the parent it has in the collection
208
+ * so it can be used without querying the database.
209
+ *
210
+ * @return $this
211
+ */
212
+ public function setParents()
213
+ {
214
+ $this->setParentsRecursive($this);
215
+ return $this;
216
+ }
217
218
+ protected function setParentsRecursive(&$items, &$parent = null)
219
220
+ foreach ($items as $item) {
221
+ if ($parent) {
222
+ $item->setRelation('parent', $parent);
223
224
+ $this->setParentsRecursive($item->items, $item);
225
226
227
0 commit comments