Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

laravel

Here is my code in the routes.php file:

Route::auth();

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

Route::auth()->middleware('setLang');

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?

like image 937
stack Avatar asked Dec 09 '25 19:12

stack


1 Answers

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

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

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

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

like image 178
Alexey Mezenin Avatar answered Dec 12 '25 09:12

Alexey Mezenin