From 7dc69fec2eb7f2eadedbc43d0b5a117d565b1958 Mon Sep 17 00:00:00 2001 From: Chris Morrell Date: Mon, 6 Nov 2023 00:07:04 -0500 Subject: [PATCH] Dynamic routes --- composer.json | 2 +- src/VerbsServiceProvider.php | 10 ---------- workbench/routes/web.php | 15 ++++++++++++--- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index 157faa79..d5b1e7fb 100644 --- a/composer.json +++ b/composer.json @@ -70,7 +70,7 @@ "Thunk\\Verbs\\Examples\\Monopoly\\": "examples/Monopoly/src/", "Thunk\\Verbs\\Examples\\Monopoly\\Tests\\": "examples/Monopoly/tests/", "Thunk\\Verbs\\Examples\\Monopoly\\Database\\Factories\\": "examples/Monopoly/database/factories/", - + "Workbench\\App\\": "workbench/app/", "Workbench\\Database\\Factories\\": "workbench/database/factories/", "Workbench\\Database\\Seeders\\": "workbench/database/seeders/" diff --git a/src/VerbsServiceProvider.php b/src/VerbsServiceProvider.php index 95813123..818a584a 100644 --- a/src/VerbsServiceProvider.php +++ b/src/VerbsServiceProvider.php @@ -70,15 +70,5 @@ public function boot() $this->app->make(Broker::class)->fire($event); } }); - - // $this->publishes([ - // __DIR__.'/../config/verbs.php' => config_path('verbs.php'), - // ], 'verbs-config'); - - // $this->publishes([ - // __DIR__.'/../database/migrations/create_verb_events_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_create_verb_events_table.php'), - // __DIR__.'/../database/migrations/create_verb_snapshots_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_create_verb_snapshots_table.php'), - // __DIR__.'/../database/migrations/create_verb_state_events_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_create_verb_state_events_table.php'), - // ], 'verbs-migrations'); } } diff --git a/workbench/routes/web.php b/workbench/routes/web.php index 93bf7113..da6a481e 100644 --- a/workbench/routes/web.php +++ b/workbench/routes/web.php @@ -1,7 +1,16 @@ group(function () { - require __DIR__.'/../../examples/Monopoly/routes/web.php'; -}); +// Dynamically load all examples into their own prefixes +FinderCollection::forDirectories() + ->depth(0) + ->inOrEmpty(__DIR__.'/../../examples') + ->each(function (SplFileInfo $file) { + if (file_exists($routes = "{$file->getRealPath()}/routes/web.php")) { + Route::prefix(str($file->getBasename())->kebab()->toString()) + ->group(fn () => require $routes); + } + });