K
K
Ken Jee2018-02-06 16:18:44
Laravel
Ken Jee, 2018-02-06 16:18:44

How to completely move authorization in Laravel 5.5 to a prefix?

Connected the authorization mechanism to the site

php artisan make:auth

By default, all actions login, logout, home, etc. hang at the first level of the URL hierarchy. And you need to move them to the /user/ level, i.e. /user/login, /user/logout, /user/home, etc. To do this, I use a group ...
Route::group( ['middleware' => ['web'] ], function () {
Route::group(['prefix' => 'user', 'middleware' => ['auth']], function () {
Route::get('/home', '[email protected]')->name('home');
});
});

But the prefix works for the home action, while the rest remain at the same level. Those. specifying /user/home redirects me to /login (because I'm not authorized). Where and how should these routes be edited?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Ramm, 2018-02-06
@Machez

Route::group(['prefix' => 'user'], function () {
    Auth::routes();
});

A
Andreo, 2018-02-06
@chupacabramiamor

Try like this:

Route::group( ['middleware' => ['web'] ], function () {
    Route::group(['prefix' => 'user'], function () {
        Route::get('/login', '[email protected]')->name('login');
        Route::group(['middleware' => ['auth']], function(){
            Route::get('/home', '[email protected]')->name('home');
            Route::get('/logout', '[email protected]')->name('logout');
        });
    });
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question