Solving the Error: route [login] not defined in laravel 5.5

Leandro Ruel
Jan 12, 2018 · 2 min read

if you are using the latest version of laravel from 5.5.* or above, and are using 1.0.0, and get this error when acessing one of your api routes:

Route [login] not defined.

this commit can be the reason:

at file: app/Exceptions/Handler.php

Taylor removed the function unauthenticated, and now the file just has the render and the report methods, not sure why he made it, i searched for a explanation but the commit message just says: “ remove things that aren’t usually customized”, the method render returns the parent render function from Illuminate\Foundation\Exceptions\Handler, this class is imported at top of Handler class with the alias “ExceptionHandler” and the Handler class extends it. the commit was merged at date: 03/01/2018 at release 5.5.28.

The render method

looking into render method at parent handler class on Laravel Api docs, the description is: Render an exception into a response.

this is the code of the parent handler class:

just look on it to understand what is happening.

My solution:

to solve this problem just do the following changes:

1 go to App\Exceptions\Handler.php

2 change the render function and remove the parent render function and instead return your own json response, like in this gist:

not sure if it still is the best approach to use, i’m just doing my app in development environment, so maybe i can change this solution later, comment and tell me if you find any solution better than this.

(sorry for my english i’m brazilian) thanks! :)

here a few links related:

Leandro Ruel

Written by

gosta de trabalhar com #frontend e curte HQs, Animes e comer porcaria