Skip to content

Commit

Permalink
Register theme controllers in routing
Browse files Browse the repository at this point in the history
  • Loading branch information
Timot Tarjani committed Feb 23, 2024
1 parent 29e86d9 commit 1becdef
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1becdef

Please sign in to comment.