Search code examples
phplaravelroutescommand-line-interface

laravel route:list filter by controller


In my Laravel 10 project, I have two controllers with the same name but in a different namespace. For these controllers I would like to list all the routes in my CLI, thus I would like to filter my routes in my CLI based on controller name.

You can find the filter flags for the route:list command by typing php artisan route:list --help as it will contain the following output (output shortened for brevity):

Options:
      --method[=METHOD]            Filter the routes by method
      --name[=NAME]                Filter the routes by name
      --domain[=DOMAIN]            Filter the routes by domain
      --path[=PATH]                Only show routes matching the given path pattern
      etc...

As you can see, no filter for the controller name is given. How can one still get a list of all routes that have a given controller name?


Solution

  • Since there is no filter option for this type of search (yet), one can use a work around using a tool like grep as so: php artisan route:list | grep 'Namespace\\Controller'. Note that in order to make it work, I needed to double the slash.

    Unfortunately, as a side effect, the colors of my output get removed. Using grep --color=always did not solve this issue.