Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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();
});
like image 727
TaeKwonDev Avatar asked Oct 20 '16 13:10

TaeKwonDev


People also ask

What is the use of Route group in Laravel?

Routes Groups are helpful in the situation when you want to apply one attribute to all the routes. Laravel 8 route groups allow you to group all the routes related to your modules. Route group takes an array that can take attributes and callback function.

How to prefix each route name with a string in Laravel?

The name method is used to prefix each route name with some specified string. In the name method, we need to specify the string with a trailing character in the prefix. Let's see an example. In the above code, the name of the route would be admin.users.

How to validate a subdomain in Laravel route?

We can validate it directly in the route, with “where” parameter: The main part here is ‘where’ => [‘locale’ => ‘ [a-zA-Z] {2}’] where we use a regular expression to match only two-letter combinations. Tip 4. Dynamic Subdomain Routing This comes directly from the official Laravel documentation, but rarely used so I think to mention it.

How do I prefix or name a group of routes?

The prefix method may be used to prefix each route in the group with a given URI. For example, you may want to prefix all route URIs within the group with admin: The name method may be used to prefix each route name in the group with a given string. For example, you may want to prefix all of the grouped route's names with admin.


1 Answers

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')
like image 142
Shahid Ahmad Avatar answered Nov 15 '22 03:11

Shahid Ahmad