'categories/(:any)', 'action' => function ($category) { $allTexts = page('textes')->grandChildren(); $textsInCategory = $allTexts->filter( fn($text) => Str::slug($text->category()) === $category ); $children = new Pages(); foreach ($textsInCategory as $text) { $children->add($text); } $title = $textsInCategory->first()->category(); return Page::factory([ 'slug' => Str::slug($category) . '-' . Uuid::generate(), 'template' => 'category', 'model' => 'category', 'content' => [ 'title' => $title, 'uuid' => Uuid::generate(), ], 'children' => $children->toArray(), ]); }, ];