That is hard to say without seeing anything. I can recommend that you start by comparing the RouteServiceProvider from a new installation with yours
Artisan route:list not showing any routes
Hi,
I have a project which the previous developers have altered some of the laravel configurations, the project started from laravel 5.1 and upgraded to laravel 9. The project is currently working but when I try to run php artisan route:list there is no route showing off. I already checked the configurations updates of laravel from the main repository itself and updated also the project.
How can I make it show when running that command/What should I do to make it show/Which file should I check to make sure everything is correct?
@Sinnbeck Hi sorry for not sharing any code, anyways below is my route service provider this is the only part differs with the latest RouteServiceProvider
protected $namespace = [
'App\Http\Controllers',
'App\Modules\Dashboard\Controllers',
'App\Modules\Management\Controllers',
'App\Modules\Scheduling\Controllers',
'App\Modules\Setup\Controllers',
'App\Modules\SystemSettings\Controllers',
];
protected $allRoutes = [
'app/Http/routes.php',
'app/Modules/Dashboard/routes.php',
'app/Modules/Management/routes.php',
'app/Modules/Scheduling/routes.php',
'app/Modules/Setup/routes.php',
'app/Modules/SystemSettings/routes.php',
];
/**
* Define your route model bindings, pattern filters, and other route configuration.
*
* @return void
*/
public function boot()
{
$this->configureRateLimiting();
$this->routes(function () {
foreach($this->namespace as $key => $val) {
Route::middleware('web')
->namespace($this->namespace[$key])
->group(base_path($this->allRoutes[$key]));
}
});
}
All of the imports are the same, already updated packages also and compared the file from this RouteServicePRovider
@peeknot any change if you run php artisan route:cacheor php artisan route:clear
Do you have xdebug installed?
@Sinnbeck nothing changes after that command, havent installed xdebug also.
@peeknot show your web.php file code here?
@Shivamyadav it is basically empty since we altered the route file to be placed inside each modules
So if the structure of project is
Module A = Controllers/Models/Views and then have a routes.php file and so on
See image for sample
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
@peeknot ok. See if it can resolve the routes. Could be the command that is the problem
use Illuminate\Routing\Router;
Route::('test', function (Router $router) {
dd($router->getRoutes());
});
@Sinnbeck it shows all the routes by using this one
@peeknot so it seems to resolve correctly. Any chance they have overwritten the command? Check if you have a command using the same name
Or find the command in the vendor folder and use dd() to see where it breaks https://github.com/laravel/framework/blob/9.x/src/Illuminate/Foundation/Console/RouteListCommand.php
@Sinnbeck I just checked the command with name route:list it doesnt have anything.
I just checked also the RouteListCommand.php file, it returns nothing on class getRoutes
protected function getRoutes()
{
$routes = collect($this->router->getRoutes())->map(function ($route) {
return $this->getRouteInformation($route);
})->filter()->all();
The routes variable has empty values, but on the mapping the route has value, shows all the route information below is the sample output
array:7 [ // vendor\laravel\framework\src\Illuminate\Foundation\Console\RouteListCommand.php:156
"domain" => null
"method" => "GET|HEAD"
"uri" => "sanctum/csrf-cookie"
"name" => null
"action" => "Laravel\Sanctum\Http\Controllers\CsrfCookieController@show"
"middleware" => "web"
"vendor" => true
]
The output of the routes inside the map, I just copy paste a chunk of the output
"POSTgrading-system/deportment/event" => Illuminate\Routing\Route^ {#957 …18}
"HEADgrading-system/checklist" => Illuminate\Routing\Route^ {#958 …18}
"POSTgrading-system/checklist/event" => Illuminate\Routing\Route^ {#959 …18}
"HEADgrading-system/checklist/search" => Illuminate\Routing\Route^ {#960 …18}
"HEADclass-record/schedules" => Illuminate\Routing\Route^ {#962 …18}
"HEADclass-record/schedules/action" => Illuminate\Routing\Route^ {#963 …18}
"POSTclass-record/schedules/data" => Illuminate\Routing\Route^ {#964 …18}
@peeknot so if I understood correctly, it's empty after the filter?
@Sinnbeck yes exactly
@peeknot so it seems your custom routes does not return any route information. This is where xdebug would come in handy. But use dump() to see why it returns nothing for your routes
@Sinnbeck I found the problem, my middleware has 2 set of data, the must only have 1 which is web now Im trying to find which part of the configuration this registers.
array:2 [ // vendor\laravel\framework\src\Illuminate\Foundation\Console\RouteListCommand.php:159
0 => "web"
1 => "App\Http\Middleware\RedirectIfAuthenticated"
]
Try this
create controller by this command php artisan make:controller TestController
and use it in your web.php file
import in the top of the file use App\Http\Controllers\TestController;
and then create this route
Route::resource('/test', TestController::class);
and then try to run the commnad php artisan route:list
Please or to participate in this conversation.