Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel folder structures

Often i come find it problematic when deciding where to place folders to resources within the app\ folder.

Where should i place things such as model observers and validators and form macros and repositories.... currently i do the following

\app
   \models
   \controllers
   \repositories
   \observers
   \interfaces
   \validators 
   \views

although i see some people do the following:

\app
   \models
   \controllers
   \views
   \YourAppNameHere
      \Services
         \validators
         \...

I do not understand the reason behind the \Acme folder when its the same as the actual application?

like image 902
AndrewMcLagan Avatar asked Jan 27 '14 11:01

AndrewMcLagan


1 Answers

Best way to master Laravel folder structure is to treat app directory as a front end of framework. If you take a look at the git repository you'll see that they are separated - you can clone core library and you can clone laravel application alone. Application, with it's subfolders represents just one way in which framework can be used. Ofcourse, it is designed with best practices involved. Check out also core framework tests directory - there Laravel developers treated library as "headless" - without application. For me, it was everything I need to grasp Laravel.

So you are free to modify existing structure, but keep in mind that some changes require you to composer dump-autoload - mostly because of namespaces.

like image 197
Miroslav Trninic Avatar answered Oct 13 '22 06:10

Miroslav Trninic