Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Akeno's avatar

php artisan route:list returns error

Hi, I wanted to see all my routes, so I typed:

'php artisan route:list'

And I get this error:

[Symfony\Component\Debug\Exception\FatalErrorException]
  Call to a member function getName() on a non-object

I looked it up in the log files, the problem is inside of a controller. This line is causing the error:

$this->routeName = $request->route()->getName();

$request->route() somehow returns 'null' but I don't know why :/

I don't know where I should start looking to fix this problem that's why I can't really give any other information. Maybe you have an idea?

Thank you

Dennis

0 likes
6 replies
bobbybouwmann's avatar

you are calling that in one of your controllers right? Otherwise it wouldn't throw that error..

Akeno's avatar

But it worked this way for quite a while now. What changed?

Is there a better way to get the route's name?

bobbybouwmann's avatar
Level 88

When you run route:list you are not accessing a route so the function fails. You can simply check if route exists before you get the name

$this->routeName = $request->route() ? $request->route()->getName() : '';
4 likes
Akeno's avatar

Oh, right.

Didnt see that :D

Thank you! ;)

Please or to participate in this conversation.