Laravel 5.3 change login path and prevent registration

Prevent that /login is the default path for login

Thanks to Stackoverflow. Go to your routes/web.php

And change:

Auth::routes();

Into:

// Login
Route::group(['middleware' => ['web']], function() {
    Route::get('login-new-address', ['as' => 'login', 'uses' => 'Auth\LoginController@showLoginForm']);
    Route::post('login-new-address', ['as' => 'login.post', 'uses' => 'Auth\LoginController@login']);
    Route::post('logout-new-address', ['as' => 'logout', 'uses' => 'Auth\LoginController@logout']);
});
// Registration Routes...
    Route::get('register', ['as' => 'register', 'uses' => 'Auth\RegisterController@showRegistrationForm']);
    Route::post('register', ['as' => 'register.post', 'uses' => 'Auth\RegisterController@register']);

// Password Reset Routes...
    Route::get('password/reset', ['as' => 'password.reset', 'uses' => 'Auth\ForgotPasswordController@showLinkRequestForm']);
    Route::post('password/email', ['as' => 'password.email', 'uses' => 'Auth\ForgotPasswordController@sendResetLinkEmail']);
    Route::get('password/reset/{token}', ['as' => 'password.reset.token', 'uses' => 'Auth\ResetPasswordController@showResetForm']);
    Route::post('password/reset', ['as' => 'password.reset.post', 'uses' => 'Auth\ResetPasswordController@reset']);

Would you like to prevent registration?

Remove the registration and password reset routes if you don’t want people to register, e.g. for admin panels.

Also change your redirect if not logged in

Change in App/Exceptions/Handler.php the redirect to:

return redirect()->guest('login-new-address');


Laravel 5.1 logout custom message and redirect to previous page

When you’re logging out in Laravel 5 and 5.1 the AuthenticatesUsers is called and the getLogout method. Since, it’s in the Illuminate directory it’s not nice to write in this file directly. It’s better to rewrite the getLogout method from an Auth\AuthController.

Normally AuthCntroller, it might use this traits:

use AuthenticatesAndRegistersUsers, ThrottlesLogins;

Now we’ll rename the getLogout of the AuthenticatesUsers trait:

use AuthenticatesAndRegistersUsers
    {
        getLogout as authLogout;
    }
    use ThrottlesLogins;

Now we can rewrite the getLogout and still use/inherit the old trait’s class:

    /**
     * Overwrite getLogout method of trait AuthenticatesUsers and calls it again, since it's renamed as $this->authLogout();
     * @return Response
     */
    public function getLogout()
    {
        if (!empty(URL::previous()) && !str_contains(URL::previous(), "auth/"))
        {
            $this->redirectAfterLogout = URL::previous(); // Send back to previous url if possible
        }

        alert()->success('You\'re logged out', 'Logout'); // Send a flash message e.g. with the SweetAlert package: https://github.com/uxweb/sweet-alert
 
        return $this->authLogout(); // rest of the old method of the trait
    }