stack stack - 11 months ago 50
PHP Question

How to apply an middleware on ::auth()?

Here is my code in the



Now I need to put a middleware on the way of that route. Something like this:


But in this case, it throws this error:

FatalErrorException in routes.php line 43:
Call to a member function middleware() on null

How can I fix it?

Answer Source

To make it work, you first need to register middleware.

After that use group() method to set middleware property:

Route::group(['middleware' => 'setLang'], function () {

If you still get Class not found error, try to run composer dumpauto command.