Search code examples
laravelrouteslaravel-5.3

Can I register Laravel Auth::routes() under a prefix group?


Hi I'm working with Laravel 5.3 and I notice that the default Auth routes are registered using Auth::routes();. Is it possible to encapsulate these routes under a prefix group? Eg:

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

Solution

  • Yes You can use it but to make sure now you should prefix your url with admin

    e.g If previously you access your url like http://localhost/auth/login

    Now you should prefix your url with admin before auth like below http://localhost/admin/auth/login

    Issue is in your middleware you use auth middleware

    Go to App/http/Middleware/Authenicate.php and there go to handle mathod in a class. There you see return redirect()->guest('auth/login'); please replace it with

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