简体   繁体   中英

how to define laravel 5.0 routes by means of directories

I would like to do this thing with laravel 5.0. I would have many routes.php files in some folders (like, under the app/ folder, I create a "linux" folder and a "windows" folder). Inside the two linux and windows folders, i put two routes.php files, with different routes (like, i don't know, they both have the route get('os') ). What I want is that calling public/windows/os it is called the route os of the windows folder, and calling public/linux/os it is called the route os of the linux folder (basic polimorphism). I searched over and over and found nothing helpful. Do you have some advice? Thanks.

You can simply include the other route files in your main routes.php and put them inside route groups:

Route::group(['prefix' => 'windows'], function(){
    include app_path('windows/routes.php');
});

Route::group(['prefix' => 'linux'], function(){
    include app_path('linux/routes.php');
});

To reduce the duplicate code you can also use an array to configure your subdirectories:

$systems = ['windows', 'linux'];
foreach($systems as $os){
    Route::group(['prefix' => $os], function(){
        include app_path($os.'/routes.php');
    });
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM