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

Leandro Ruel
2 min readJan 12, 2018

--

if you are using the latest version of laravel from 5.5.* or above, and are using https://github.com/tymondesigns/jwt-auth 1.0.0, and get this error when acessing one of your api routes:

Route [login] not defined.

this commit can be the reason: https://github.com/laravel/laravel/commit/134eafd12cde2e0d7b6ebea8b42b5454a20afda3#diff-646a4842abf9023c975a9a1658a68b0aL80

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:

https://stackoverflow.com/questions/45340855/laravel-5-5-change-unauthenticated-login-redirect-url

--

--

Leandro Ruel

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