Help with middleware group

0

My web.php file looks like this:

Route::get('/login', 'AutenticacaoController@login')->name('autenticacao.login');
Route::post('/logar', 'AutenticacaoController@logar')->name('autenticacao.logar');
Route::resource('autenticacao', 'AutenticacaoController');

Route::middleware(['auth'])->group(function(){
    Route::get('/', 'MunicipioController@inicio')->name('inicio');
    Route::get('/logout', 'AutenticacaoController@logout')->name('autenticacao.logout');
    Route::resource('municipios', 'MunicipioController');
});

If I access the route localhost/login , I get good access, but if I access localhost/ , I get the error:

  

Route [login] not defined.

What could be wrong?

The idea is that, when accessing localhost/ , it is redirected to localhost/login

    
asked by anonymous 08.09.2018 / 15:24

1 answer

1

When you use Laravel's default Middleware, it sets some name of default routes. In your case, you protected the localhost/ route but did not set name to login on some other route so that Laravel could redirect when the user was not logged in.

Just change from:

Route::get('/login', 'AutenticacaoController@login')->name('autenticacao.login');

To:

Route::get('/login', 'AutenticacaoController@login')->name('login');

In detail, Laravel uses the name function to redirect, so long as it is login , you can define your login path as you want.

If you want to change other Auth routes, see this link .

    
08.09.2018 / 18:41