Laravel - Routing

Hi,

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;

-app
      - 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.
SheppardDigitalAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
My experience is with Laravel 4.2 (5.0 seems to be current / recent).  If you choose "resourceful" routing, Laravel will assume that you are using the default set of named routes.  However if you forgo the default and name your routes explicitly, Laravel will use introspection* to examine its own code and your routes, and will set up the routing correctly.

* In PHP I think this might be called Reflection.

Suggest you experiment with this a little bit - I had to at first but after a few different attempts it made a lot of sense.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.