Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple route file instead of one main route file in laravel 5

Tags:

php

laravel

I am a novice in web developing with Laravel 5. I installed asGgardCMS and After seeing asgardCms codes, I found that there is nothing codes in app/Http/route.php file and required codes for routing be placed in Modules codes. For example required code for routing menu manager module be placed in Modules/Media/apiRoutes.php and Modules/Media/backendRoutes.php files. May help me and tell me how I can manage my routes like that?

like image 305
loghman Avatar asked Dec 09 '15 15:12

loghman


People also ask

What are the default route files in Laravel?

The Default Route Files The routes/web.php file defines routes that are for your web interface. These routes are assigned the web middleware group, which provides features like session state and CSRF protection. The routes in routes/api.php are stateless and are assigned the api middleware group.


1 Answers

You can create as many route files as you need anywhere and then just require them in the main route file smth like:

Route::get('/', function () {
    return 'Hello World';
});

Route::post('foo/bar', function () {
    return 'Hello World';
});

require_once "../../myModule1/routes.php";
require_once "../../myModule2/routes.php"
require_once "some_other_folder/routes.php"

where you will define routes in the same way as in main

like image 132
Silwerclaw Avatar answered Sep 19 '22 21:09

Silwerclaw