Yep, it's another Laravel route not found issue! This is actually quite an odd one. I am aware there are multiple issues here with the same error message at least, but none that seem to be the same as mine.
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
and php artisan route:clear
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.
UPDATE: 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.
composer dump-autoload
? - linktoahrefphp artisan module:enable Finances
- linktoahrefModule [Finances] has already enabled.
is unfortunately the message I get. - CGriffincomposer.json
have you made an entry"Modules\\": "Modules/"
under psr-4 autoloading? - linktoahref