We help IT Professionals succeed at work.
Get Started

Laravel - Routing

Last Modified: 2015-03-07

For the past number of years my projects have been based on my own PHP framework, it's simple, but has worked.

I've started to look into other framework and Laravel seems to come top of mosts lists I look at. I've started looking at the possibility of using it in future projects, but there seems to be something I don't know if it can do.

Firstly, my frame has a folder structure like this;

      - routes
          - admin
               - controller
               - view
               - www
          - api
               - controller
          - public
               - controller
               - view
               - www

Urls such as www.domain.com/public/ are mapped to /app/routes/public/, and www.domain.com/admin/ are mapped to /app/routes/admin/. I like doing is this way as it keeps admin interface files away from public facing files, it's much more organised in my opinion.

Secondly, in my framework I don't need to define each route as you do in Laravel. /admin/users/list_active/ loads the list_active() method that's in the users controller inside the admin route folder.

Most of the projects I work on involve an admin interface, and an API. Can I do the above in Laravel without having all of the controllers in one place. I really don't like the idea of having to prefix controller names with api-userController, or admin-userController, it just feels messy and un-organised.

Is there a way to have Laravel catch all routes and automatically route them to the correct controller/method? In hindsight I don't think I might too much having to define routes, as I can see the benefits in doing this for API's i.e. /user/69/messages/h76dg/ being mapped to user::messages($user_id,$message_id);

Any help would be appreciated.
Watch Question
Most Valuable Expert 2011
Author of the Year 2014
This problem has been solved!
Unlock 1 Answer and 1 Comment.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE