Laravel Route List (php artisan route:list) Displaying Middleware on New Lines

Viewed 6933

I have noticed recently a change in the way that my Laravel project is rendering the route list in the terminal. It is no longer comma separating the middleware column, and if there is more than one middleware it will add it to a new blank row in the table underneath its parent route.

This may seem like a very trivial problem, however being relatively new to laravel and this being my first proper project I have been producing with it I am firstly concerned that there could be an issue with the laravel install somehow that may cause other issues elsewhere, and the more routes I add with various middleware, the table when displaying all routes is becoming rather difficult to interoperate, where this was not an issue before.

See below a screenshot of the route table filtered to show only a select number of the routes in my project in order to give you an idea of what I am seeing.

Route table

Would anyone know why this has changed, and if there is a way to get it back to displaying it as it was before, by keeping all the middleware on the row with all the other data, and comma separating them.

On a whim, I have tried the following in the console, and they have made no difference:

php artisan cache:clear php artisan routes:clear php artisan config:clear

To be clear, what I expect to see is something like this:

Route table

3 Answers

If you want to add semicolon again

Go to your project file vendor\laravel\framework\src\Illuminate\Foundation\Console then open file RouteListCommand.php

search for function getMiddleware

protected function getMiddleware($route)
    {
        return collect($this->router->gatherRouteMiddleware($route))->map(function ($middleware) {
            return $middleware instanceof Closure ? 'Closure' : $middleware;
        })->implode("\n");
    }

just change \n to , in implode

Here is the fix, if you are still facing issues in Laravel 8 with Sanctum.

I have replacedon this line

return collect($this->router->gatherRouteMiddleware($route))->map

with this line on

return collect($route->gatherMiddleware())->map

in Laravel's core file. Usually, this is not recommended, but I need a solution. You can also try if needed.

For more details, please visit the below link and refer to my comment on this page.

https://github.com/laravel/framework/commit/7ebd21193df520d78269d7abd740537a2fae889e

Related