I am using the nWidart/laravel-modules (https://github.com/nWidart/laravel-modules) package for Laravel to create a module-based setup. I began with a fresh install of Laravel 5.4 via Composer, then generated the basic user authentication via php artisan make:auth
. After basic setup, my app/Http/routes.php
file looks like this:
// home page
Route::get('/', function () {
return view('welcome');
});
// login, logout, register, etc.
Route::auth();
// admin dashboard
Route::get('/admin', 'AdminController@index');
I then installed the modules package via Composer and ran php artisan module:make Finances Jobs Etsy
to create three modules, Finances, Jobs, and Etsy. This ran without incident. I then went into the Http/routes.php
file for each individual module and added the auth
middleware and an additional prefix to each route group:
// Finances routes file
Route::group(['middleware' => ['web', 'auth'], 'prefix' => 'admin/finances', 'namespace' => 'Modules\Finances\Http\Controllers'], function()
{
Route::get('/', 'FinancesController@index');
});
// Jobs routes file
Route::group(['middleware' => ['web', 'auth'], 'prefix' => 'admin/jobs', 'namespace' => 'Modules\Jobs\Http\Controllers'], function()
{
Route::get('/', 'JobsController@index');
});
// Etsy routes file
Route::group(['middleware' => ['web', 'auth'], 'prefix' => 'admin/etsy', 'namespace' => 'Modules\Etsy\Http\Controllers'], function()
{
Route::get('/', 'EtsyController@index');
});
Now here is the very frustrating issue: all the base app routes work fine. The home page route, the auth routes, and the /admin
route all work perfectly. In addition, all the Jobs
module routes work perfectly as well. However, any and all routes from the Finances
and Etsy
modules do not work. Trying to access https://[site url]/admin/finances
shows me the following error:
NotFoundHttpException in RouteCollection.php line 161:
Which to me says, Laravel can't find the given route, despite being able to find the route for the Jobs module.
Extra confusingly, it sort of seems like Laravel can find the routes, as running php artisan route:list
DOES show me the routes for the Finances and Etsy modules.
I have also tried running php artisan cache:clear
, php artisan route:clear
, and composer dump-autoload
multiple times, in case it was some sort of caching issue. No luck.
So at this point I have absolutely no idea what to make of all this. I've got three modules, one whose routes are working perfectly, and two others, whose identically-configured routes are not working at all, yet are being found by route:list
. I'm pretty much out of ideas as to what the issue could be at this point.
Interestingly, if I place the route in the base app routes.php
file like so:
Route::group(['middleware' => ['web', 'auth'], 'prefix' => 'admin/finances'], function()
{
Route::get('/', '\Modules\Finances\Http\Controllers\FinancesController@index');
});
Then the route does work. So it seems to be an issue where the web application specifically can't seem to find the routes.php
files for those two modules, but the console application can.
Just a quick update on this issue: still no progress. I've even tried reinstalling Laravel fresh, and the same issue occurs - very strangely, the exact same issue, whereby only the Jobs
module's routes will work. I've tried making some more modules and none of their routes are found by the web application either - so the 'Jobs' module is the anomaly for working, as no other module seems to work, despite the correct entry being made in the PSR-4 autoload section of the application's composer.json
.
And another update: I had enough and hard-rebooted my server. And... now even the jobs routes don't work. I have utterly no idea what's going on, but at least I have consistent behaviour from these modules now.
Hey,
You can have a look at this thread https://github.com/nWidart/laravel-modules/issues/118 . It should solve the problem.
in the file config/modules.php
Change
'scan' => [
'enabled' => false,
'paths' => [
base_path('vendor/*/*'),
],
],
to
'scan' => [
'enabled' => true,
'paths' => [
base_path('modules/*'),
],
],
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community