Change the login/register URL in Laravel 5.5 Hi i use laravel 5.5 and im currently writing an application which only has accounts for staff of the company, not regular website visitors. As such, I would like to keep my URLs which relate to the 'admin' area of the site, under the /admin URL which means changing /login to /admin/login and /register to /admin/register.
In your routes\web.php file, replace the Auth::routes(); with the following:
// Authentication Routes...
$this->get('admin/login', 'Auth\LoginController@showLoginForm')->name('login');
$this->post('admin/login', 'Auth\LoginController@login');
$this->post('admin/logout', 'Auth\LoginController@logout')->name('logout');
// Registration Routes...
$this->get('admin/register', 'Auth\RegisterController@showRegistrationForm')->name('register');
$this->post('admin/register', 'Auth\RegisterController@register');
// Password Reset Routes...
$this->get('admin/password/reset', 'Auth\ForgotPasswordController@showLinkRequestForm')->name('password.request');
$this->post('admin/password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail')->name('password.email');
$this->get('admin/password/reset/{token}', 'Auth\ResetPasswordController@showResetForm')->name('password.reset');
$this->post('admin/password/reset', 'Auth\ResetPasswordController@reset');
Thank you works but i want users with no account to not have access to my admin page and all the sub folders under the admin
Add auth middleware in a group around your admin routes like this:
Route::group(['middleware' => ['auth', 'web']], function () {
// your routes go here
});
To change the login URL's you should look for the Route::auth() method inside your routes/web.php and remove it. Override with:
Route::get('/admin/login', 'Auth\AuthController@showLoginForm');
Route::post('/admin/login', 'Auth\AuthController@login');
Route::get('/admin/logout', 'Auth\AuthController@logout');
Note:
Route::auth() automatically handles login, logout and register.
Hello, guys, I've tried this method on the latest version of laravel 7.x but it didn't work but I have made a research and finally, I got an answer!
Route::group(['prefix' => 'admin'], function () {
Auth::routes();
});
Please sign in or create an account to participate in this conversation.