DEV Community

Discussion on: How to separate your Routes at Laravel conveniently.

Collapse
 
naveedali8086 profile image
Naveed Ali

Assalamu Alikum Mohammed Osama,

I have one question and one suggestion.

question:
what difference you consider between guest and public routes?

suggestion:
you can include your 'extra route files/sub_route files' in web.php and api.php files (using the php's include()/require()). it has two benefits:

  1. you will not have to define same route in two different files (i.e. in web.php and api.php).

  2. you don't have to write multiple multiple functions in RouteServiceProvider

Correct me if am wrong

Collapse
 
secmohammed profile image
mohammed osama

Salam Naveed,

concerning the question:
the public route doesn't matter whether you are currently authenticated or not, you can view these routes in either case.
guest routes can only be shown when you aren't logged in, such as login/register routes.

concerning the suggestion:
I don't need to require the files inside the web.php/api.php as it will be repetitive for each file we are going to require, we will have to define its middleware which will end up doing the same logic I'm trying to achieve by the service provider, but without writing the same requiring and assigning the middleware.
concerning the first point, It's better to not have the same route at api/web, because they both have different middleware groups.