laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.21k stars 10.9k forks source link

The "route:list" command displays/output all attached Middleware. #33041

Closed TiBianMod closed 4 years ago

TiBianMod commented 4 years ago

Description:

This issue/behavior is introduced on Laravel Version 7.13.0 and specific on commit (https://github.com/laravel/framework/commit/7ebd21193df520d78269d7abd740537a2fae889e). The "route:list" command will output all the attached Middleware per route after installing Laravel Sanctum.

Steps To Reproduce:

laravel new app

List all routes

php artisan route:list
Screenshot 2020-05-31 at 18 52 49

All Good and Nice :)

Now lets install Laravel Sanctum

composer require laravel/sanctum

List all the routes again

php artisan route:list
Screenshot 2020-05-31 at 18 54 17

Related commit (https://github.com/laravel/framework/commit/7ebd21193df520d78269d7abd740537a2fae889e)

kiddtang commented 4 years ago

i am not using laravel/sanctum, but it happen after the composer update

Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Package operations: 0 installs, 23 updates, 0 removals
  - Updating doctrine/cache (1.10.0 => 1.10.1): Loading from cache
  - Updating doctrine/inflector (2.0.1 => 2.0.2): Loading from cache
  - Updating doctrine/lexer (1.2.0 => 1.2.1): Loading from cache
  - Updating guzzlehttp/guzzle (6.5.3 => 6.5.4): Loading from cache
  - Updating voku/portable-ascii (1.4.10 => 1.5.1): Loading from cache
  - Updating vlucas/phpdotenv (v4.1.5 => v4.1.6): Loading from cache
  - Updating symfony/event-dispatcher-contracts (v2.0.1 => v2.1.2): Loading from cache
  - Updating symfony/service-contracts (v2.0.1 => v2.1.2): Loading from cache
  - Updating opis/closure (3.5.1 => 3.5.3): Loading from cache
  - Updating symfony/translation-contracts (v2.0.1 => v2.1.2): Loading from cache
  - Updating nesbot/carbon (2.34.0 => 2.35.0): Loading from cache
  - Updating monolog/monolog (2.0.2 => 2.1.0): Loading from cache
  - Updating league/flysystem (1.0.68 => 1.0.69): Loading from cache
  - Updating laravel/framework (v7.11.0 => v7.13.0): Loading from cache
  - Updating cakephp/chronos (2.0.4 => 2.0.5): Loading from cache
  - Updating laravel/horizon (v4.3.2 => v4.3.3): Loading from cache
  - Updating spatie/laravel-permission (3.11.0 => 3.13.0): Loading from cache
  - Updating backpack/crud (4.1.4 => 4.1.6): Loading from cache
  - Updating backpack/generators (v3.0.1 => v3.1.0): Loading from cache
  - Updating facade/ignition (2.0.2 => 2.0.5): Loading from cache
  - Updating laravel/telescope (v3.4.0 => v3.5.0): Loading from cache
  - Updating mockery/mockery (1.3.1 => 1.4.0): Loading from cache
  - Updating phpunit/phpunit (8.5.4 => 8.5.5): Loading from cache

i am not sure which packages contributing to this issue, just giving my output for whoever looking in this issue... the middleware list become looooong expanded list...

n1crack commented 4 years ago

I have the same problem..

driesvints commented 4 years ago

This is fixed with https://github.com/laravel/framework/pull/32993 which will be in the next patch release.

plai2010 commented 4 years ago

I'm curious why installing Sanctum would cause middleware groups (e.g. 'web' and 'api') to be expanded to their classes. Is this a Sanctum issue? The fix for #32993 replaces comma with newline, so the lines are not so long, but I would much prefer to see the group names rather than the classes.

JoshuaDoshua commented 4 years ago

@TiBianMod @plai2010 do you have barryvdh/laravel-debugbar installed? removing that fixed it for me. Related issue: https://github.com/barryvdh/laravel-debugbar/issues/1046

plai2010 commented 4 years ago

Thanks @JoshuaDoshua for sharing your experience. I didn't install barryvdh/laravel-debugbar however; I cannot find it in my composer.lock or vendor either.

You have Sanctum installed, and removing DebugBar helps? Just trying to nail down the scenario.

TiBianMod commented 4 years ago

Hi @JoshuaDoshua, I don't use barryvdh/laravel-debugbar, but like I explained before, you can reproduce this issue by installing Laravel Sanctumafter creating a new Laravel app and you will see the route:list what outputs.

quangnhattran commented 4 years ago

Hi @JoshuaDoshua, I don't use barryvdh/laravel-debugbar, but like I explained before, you can reproduce this issue by installing Laravel Sanctumafter creating a new Laravel app and you will see the route:list what outputs.

Yes, I agree with you. By installing laravel/sanctum, route:list comes with all route middlewares expanded. That is really annoying :)

plai2010 commented 4 years ago

I actually don't think #32993 is the same issue as this; I would like to see this issue re-opened.

ghost commented 4 years ago

any update on this issue?

driesvints commented 4 years ago

Outputting all the middleware is intended.

ghost commented 4 years ago

I think it would be ideal to leave the format as it was before, and if you really want to show the current format, then do it through an optional parameter in the command. Like php artisan route:list --expand-middleware

driesvints commented 4 years ago

Kind of inclined to agree with you there @leo95batista. You could always attempt a PR to see if Taylor would approve it.

plai2010 commented 4 years ago

Outputting all the middleware is intended.

I noticed something to that effect in the check-in history of some code when I was looking into it. I was puzzled however that Laravel without Sanctum did not expand the middleware classes.

Either way, the behavior seems inconsistent.

ghost commented 4 years ago

I have created a pull request to solve this problem, I hope it will be accepted

ghost commented 4 years ago

My pull request was rejected, I just have to wait for someone to give a solution...

marouane-souadi commented 3 years ago

having the same proble, it was solved after removing barryvdh/laravel-debugbar

kenxu5500 commented 3 years ago

having the same problem. but you can filter the column with flag. php artisan route:list -c

zmorris commented 1 year ago

@kenxu5500 gave the cleanest solution, but here's a cross-platform one-liner if you need to see all of the columns with one row per route:

php artisan route:list | perl -pe 's/\x1b\[[0-9;]*[mG]//g' | perl -0777 -pe 's/ +\|(\r\n?|\n)/\n/g' | perl -0777 -pe 's/(\r\n?|\n)(\| +){6}/, /g'

to break it down:

# strip control characters: https://superuser.com/a/561105
# strip trailing whitespace and pipe character, substituting newline with \0 during processing via -0
# strip leading pipes and whitespace before middleware column, substituting newline with \0 during processing via -0
php artisan route:list | \
perl -pe 's/\x1b\[[0-9;]*[mG]//g' | \
perl -0pe 's/ +\|(\r\n?|\n)/\n/g' | \
perl -0pe 's/(\r\n?|\n)(\| +){6}/, /g'

Remember to change the {6} portion if you change the number of columns with the --columns[=COLUMNS] option, see php artisan route:list -h.

I haven't tested it on Windows yet, but my understanding is that perl will match any line ending with (\r\n?|\n) and then substitute the platform-specific line ending when the \n replacement is written to the output stream.

I messed around with sed and a few other methods, but unfortunately there is no cross-platform multiline search and replace regex command that isn't burdened with quirks. So I've decided to always use perl moving forward since it's available in most environments.

A better method might be to use php artisan route:list --json | jq but I haven't figured out the magic incantation to output a table yet.

https://stedolan.github.io/jq/

Other workarounds: https://stackoverflow.com/questions/62244648/laravel-route-list-php-artisan-routelist-displaying-middleware-on-new-lines