id = $model->id; $instance->name = $model->name; $instance->description_html = $model->descriptionHtml(); if ($model->cover) { $instance->cover = $files->referenceForImage($model->cover); } $instance->tags = ZipExportTag::fromModelArray($model->tags()->get()->all()); $chapters = []; $pages = []; $children = $model->getDirectVisibleChildren()->all(); foreach ($children as $child) { if ($child instanceof Chapter) { $chapters[] = $child; } else if ($child instanceof Page) { $pages[] = $child; } } $instance->pages = ZipExportPage::fromModelArray($pages, $files); $instance->chapters = ZipExportChapter::fromModelArray($chapters, $files); return $instance; } }