From 1becdef8fd8904eca25660c44bb107a66aa75e78 Mon Sep 17 00:00:00 2001 From: Timot Tarjani Date: Fri, 23 Feb 2024 12:01:01 +0100 Subject: [PATCH] Register theme controllers in routing --- routes/web.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/routes/web.php b/routes/web.php index 339650475..c2c795c69 100644 --- a/routes/web.php +++ b/routes/web.php @@ -18,6 +18,25 @@ //Route::resource('/', \App\Controllers\WebsiteController::class); +$_THEME_NAME = Settings::get('theme'); + +if (!defined('THEME_CONTROLLER_PATH')) { + define('THEME_CONTROLLER_PATH', 'themes'.DIRECTORY_SEPARATOR.$_THEME_NAME.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'Controllers'); +} + +foreach(array_diff(scandir(THEME_CONTROLLER_PATH), ['.', '..']) as $file){ + if(is_file(THEME_CONTROLLER_PATH."/".$file)){ + $actualName = pathinfo($file, PATHINFO_FILENAME); + $controller_route = strtolower(str_replace("Controller","",$actualName)); + + + Route::resource("/".$controller_route , "\Theme\\".$_THEME_NAME."\App\Controllers\\".$actualName ) + ->names(collect(['index', 'create', 'store', 'show', 'edit', 'update', 'destroy'])->mapWithKeys(function($item) use ($controller_route){ + return [$item => 'theme.'.$controller_route.'.'.$item]; + })->toArray()); + } +} + Route::any('/{slug?}/{args?}', function ($slug = "", $args = null, Request $request, Container $container) { try {