I am using "module" services providers to do things like register navigation and permissions. I am also trying to move module specific routes to a routes.php in the module and load the routes using:
$this->loadRoutesFrom(__DIR__ . '/routes.php');
as described by Laravel documentation
I have a ModuleServiceProvider class that dynamically loads each module's service provider:
public function boot()
{
$modules = array_diff(scandir(base_path() . '/modules'), array('..', '.'));
foreach ($modules as $module) {
/*
* Register paths for: config, translator, view
*/
$modulePath = base_path() . '/modules/' . $module;
$this->loadRoutesFrom($modulePath . '/routes.php');
$this->loadViewsFrom($modulePath . '/views/', $module);
$this->loadMigrationsFrom($modulePath . '/migrations');
$this->loadTranslationsFrom($modulePath . '/lang', $module);
}
}
And for example, my Locations module has a routes file:
<?php
Route::middleware('auth:web')->group(function () {
/**
* Location Module Routes
*/
Route::resource('locations', '\Modules\Location\Controllers\LocationController');
});
I have cleared my cache and routes, and am able to do a route:list showing the routes are "registered":
art route:list | grep locations
| | POST | locations | locations.store | Modules\Location\Controllers\LocationController@store | auth:web |
| | DELETE | locations | locations.onDelete | Modules\Location\Controllers\LocationController@onDelete | auth:web |
| | GET|HEAD | locations | locations.index | Modules\Location\Controllers\LocationController@index | auth:web |
| | POST | locations/create | locations.onCreate | Modules\Location\Controllers\LocationController@onCreate | auth:web |
| | GET|HEAD | locations/create | locations.create | Modules\Location\Controllers\LocationController@create | auth:web |
| | DELETE | locations/{location} | locations.destroy | Modules\Location\Controllers\LocationController@destroy | auth:web |
| | GET|HEAD | locations/{location} | locations.show | Modules\Location\Controllers\LocationController@show | auth:web |
| | PUT|PATCH | locations/{location} | locations.update | Modules\Location\Controllers\LocationController@update | auth:web |
| | GET|HEAD | locations/{location}/edit | locations.edit | Modules\Location\Controllers\LocationController@edit | auth:web |
| | POST | locations/{user}/edit | locations.onSave | Modules\Location\Controllers\LocationController@onSave | auth:web |
However, when I try to access the routes, I am redirected back to my previous page. For instance, if I am at http://127.0.0.1:8000/home and I try to navigate to http://127.0.0.1:8000/locations I am simply redirected back to /home
I have tried moving the $this->loadRoutesFrom() call to, say, the AppServiceProvider and it is still not working.
Does anyone have any suggestions as to what I may be missing here?
Thanks in advance, I look forward to any advice or comments.