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 r
You can use Request::is()
so your main routes.php
file will look like this:
if(Request::is('frontend/*))
{
require __DIR__.'/frontend_routes.php;
}
if(Request::is('admin/*))
{
require __DIR__.'/admin_routes.php;
}
You can read more here.
You can load custom route files within a Service Provider. AsgardCMS is doing it the same way, see this method in the Core RoutingServiceProvider that loads the backend routes:
https://github.com/AsgardCms/Core/blob/master/Providers/RoutingServiceProvider.php#L77
The Laravel docs provide a simple example in the package development section:
http://laravel.com/docs/5.1/packages#routing
If you just want to create a custom route file you can easily add your custom route file and register by using the web middleware name. The code is pretty simple like this.
Edit App\Provider\RouteServiceProvider.php
public function map()
{
/** Insert this Method Name **/
$this->methodicalness();
}
protected function methodicalness()
{
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/yourRouteName.php'));
}
Note: This method also works even the file is inside the folder just trace where your route file located.
Happy Coding.
My simple and fast solution for multiple route files. It works!
In web.php file, add:
foreach (glob(__DIR__. '/*') as $router_files){
(basename($router_files =='web.php')) ? : (require_once $router_files);
}
in case someone still after that
https://ctf0.wordpress.com/2016/10/01/split-routes-into-categories-in-laravel/
1- open routes/web/api.php and add
foreach (File::allFiles(__DIR__ . '/Routes') as $route_file) {
require $route_file->getPathname();
}
2- now create a new folder at the same level and call it ‘Routes‘
3- create files according to each route ex.user, post, stuff, etc… and add ur route logic as normal
The group() method on Laravel's Route, can accept filename, so we can something like this:
// web.php
Route::prefix('admin')
->group(base_path('routes/admin.php'));
// admin.php
Route::get('/', 'AdminController@index');