3

Say I have multiple "sites" (ie. backend, public frontend, private-pay-for frontend, mobile) and perhaps also would like to offer an API for some widget services or Android app. The sites will need to (at least initially) share the same Laravel instance and will be sharing some services (ie. the frontend site might call a few services from the backend site, or the backend site and an API might share some services, especially since I'm using good SoC from things like presentation logic).

Looking at Userscape's project Snappy, Taylor Otwell says they renamed the models folder to be called snappy and just added more folders for various "areas of responsibility". This was in Laravel 4 however.

Here's the Laravel 5 directory default directory structure:

app     <-- Should I rename and duplicate for backend, frontend, api...?
   Commands
   Console
   Events
   Exceptions
   Handlers
   Http
      Controllers  <-- Or add subfolders in Controllers for backend, frontend, api...?
      Middleware
      Requests
   Providers
   Services       <-- And add subfolders in Services for backend, frontend, api...?
bootstrap
config
database
public
resources
storage
tests
vendor

How should we approach the directory structure in Laravel 5 for such situations (keeping in mind concerns of namespacing)? I didn't catch any guidance on this from the docs.

prograhammer
  • 20,132
  • 13
  • 91
  • 118
  • This is not a good approach in general. **You'll end up in a tangle!** Please consider to bundle your shared code (like models) to *private* libraries via `composer`. Then you are able to split your Website/API's into separate instances of Laravel, **instead of running one, big fat bunch of code**. – mate64 Mar 25 '15 at 11:37
  • 1
    I'm not sure who downvoted me? I'm asking an important question here. I've noticed other folks very interested in this [topic here as well](https://laracasts.com/forum/?p=2267-what-is-the-most-appropriate-way-to-structure-the-domain-level-). – prograhammer Mar 25 '15 at 20:21

0 Answers0