Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

erozas's avatar

Changing login URL default on Laravel

Hey, I was just wondering how could I change the default login URL or route (auth/register). I read on some post here that you could maybe chage:

Route::controllers([ 'login' => 'Auth\AuthController', 'password' => 'Auth\PasswordController', ]);

And change Auth for something else, the thing is I was wondering if I can change it for something like "subscribe" or a translation in my language. I know that I can make that change by implementing my own authentication but I wanted to know if there's any way to change that inside Laravel.

I've been trying to inspect "AuthenticatesAndRegistersUsers" trait but I see that getRegister() takes the call and returns a view (auth.register) I know that inside this Trait you can change the redirects and it says that you can change the "loginPath" property, however I'm trying to overwrite it and hardcode it and I cant change the path.

Is there a way to customize that without implementing my own authentication?

Thanks

0 likes
12 replies
bobbybouwmann's avatar

You need to change it in your controller, for example the auth controller has a loginPath used in the trait. You can change that variable just by instantiating the variable in your controller.

class AuthController extends Controller {

    protected $loginPath = 'myAwesomeUrl';  

    use AuthenticatesAndRegistersUsers;
    
    public function __construct(Guard $auth, Registrar $registrar)
    {
        $this->auth = $auth;
        $this->registrar = $registrar;
        $this->middleware('guest', ['except' => 'getLogout']);
    }

}
3 likes
erozas's avatar

Thanks for the answer blackbird, unfortunately I did that but I'm still not able to access the login and registration views with the custom URL.

Sorry to bother but if I do "protected $loginPath = 'login'" will that take me to the login view when I do myapp.com/login? Or would that change the "register" part of the "register/login" and "register/auth".

Thanks for your time

graham's avatar

Something like this in your routes.php

get('/signup', array('as' => 'signup', 'uses' => 'Auth\AuthController@getRegister'));
post('/signup', array('as' => 'signup', 'uses' => 'Auth\AuthController@postRegister'));
get('/login', array('as' => 'login', 'uses' => 'Auth\AuthController@getLogin'));
post('/login', array('as' => 'login', 'uses' => 'Auth\AuthController@postLogin'));
get('/logout', array('as' => 'logout', 'uses' => 'Auth\AuthController@getLogout'));
get('/forgot', array('as' => 'forgot', 'uses' => 'Auth\AuthController@getLogin'));
post('/forgot', array('as' => 'forgot', 'uses' => 'Auth\AuthController@postLogin'));

or

Route::controller('/', 'Auth\AuthController');

and then add methods to your controller for:

  • getRegister
  • postRegister
  • getLogin
  • postLogin

Discussed in more detail here: https://laracasts.com/discuss/channels/general-discussion/modifying-the-laravel-5-authentication-trait

3 likes
erozas's avatar

Thanks Graham, I gave it a try and it works, sorry if I repeated a question, I used Google but I couldn't find anything similar.

graham's avatar

No problem @erozas , not many of the results here appear in Google results for some reason.

gthomas3's avatar

I was getting FileViewFinder errors after changing my routes. In 5.1 you also need to edit framework\src\Illuminate\Foundation\Auth\AuthenticatedUsers.php. There's a few places where it's hard-coded to return the default 'auth.login' view.

Derhel's avatar

Hi @gthomas3 Im a newbie in this matters, but if i edit the file you refer, will it be replaced in future composer updates?

mln.mln.mln's avatar

In Laravel 5.*

change the content of the file app/Http/Middleware/Authenticate.php

return redirect()->guest('auth/login');

to

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

1 like
revgov's avatar

In Laravel 5.3 it is:

File: app/Http/Middleware/RedirectIfAuthenticated.php

Change the line: 21

return redirect('/admin/dashboard');

to

return redirect('/your/new/path');
1 like
usman350's avatar

Route::group(['middleware' => 'web'], function () { Auth::routes(['login' => false]); Route::get('/auth/login', 'Auth\LoginController@showLoginForm')->name('login'); });

Please or to participate in this conversation.