-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
Versions:
- laravel-modules Version: 12.0
- Laravel Version: 12.0
- PHP Version: 8.4
Description:
Even if 'routes/web' in stubs.files is commented out, the mapWebRoutes() function is generated in the RouteServiceProvider, as it points to a file that does not exist, every php artisan module returns 'No such file or directory'. The right thing to do would be to check if routes/web is commented out in config/modules/stubs.files, if so, do not create this function pointing to a file that will not exist.
Steps To Reproduce:
- Comment
'routes/web'row in stubs.files in config/modules.php - Create one module:
php artisan module:make Post --api - You will see that Modules/Post/routes/web.php does not exist, but in the RouteServiceProvider there is the
mapWebRoutesfunction. - Any php artisan module command (such as
php artisan module:delete Post) will fail because the file does not exist (full error log below).
Full Log
fabio@MacBook-Pro-de-Fabio teste_backend % php artisan module:delete Post
ErrorException
require(/Users/fabio/Documents/teste/teste_backend/Modules/Post//Routes/web.php): Failed to open stream: No such file or directory
at vendor/laravel/framework/src/Illuminate/Routing/RouteFileRegistrar.php:34
30▕ public function register($routes)
31▕ {
32▕ $router = $this->router;
33▕
➜ 34▕ require $routes;
35▕ }
36▕ }
37▕
+4 vendor frames
5 Modules/Post/app/Providers/RouteServiceProvider.php:38
Illuminate\Routing\RouteRegistrar::group("/Users/fabio/Documents/teste/teste_backend/Modules/Post//Routes/web.php")
6 Modules/Post/app/Providers/RouteServiceProvider.php:28
Modules\Post\Providers\RouteServiceProvider::mapWebRoutes()I'm posting this issue to see if I'm doing everything right. Since I'm new to the lib, I might be doing something wrong. If it really is a problem, I thought I'd check the solution and create a PR.
In reality, this doesn't just break the php artisan module command, it breaks the entire environment. Even starting a normal server (whether it's Docker, php artisan serve, etc.) breaks everything.
I know how to solve this, but I don't know the best way to do it. Initially, I thought about creating a check in the map function of the route-provider.stub file that checks if routes/web is enabled in config/modules. Otherwise, the $this->mapWebRoutes() function isn't called automatically, but I'm not sure if I have access to config/modules.
So, I thought about accessing src/Commands/Make/RouteProviderMakeCommand.php and running the check there, but I wasn't sure if the best approach would be to make the getWebRoutesPath/getApiRoutesPath functions return null when disabled, or to check first. In either case, I would have to modify the route-provider.stub file. Since I'm new to the library, I can't contribute much, but I'd love to help.
I can solve it by creating the stubs and editing the route-provider.stub.