3

Standard Laravel structure is

app
---http
------Controllers
---------MyComponentController
---Models
------MyComponentModel
---database
------MyComponentnMigration

I wonder if there is the chance to change the folder structure to:

app
---MyComponent // kind of a package that holds all mandatory elements 
------Controllers
---------Controller
------Models
---------Model
------database
---------Migration

as it would make much more sense.

update

**why does people vote it down ? it is a serious question, a model has a dependency to a migration. so if you want to use the model in another project you have to search the migration in the project and all other relevant items that has a connection with it. if all mandatory files would be structured under one parent node it would be just a copy and paste.

It would be at least honest to understand why those down voters think this isn't a good idea **

user7646471
  • 352
  • 3
  • 11
  • 4
    Yes, you may do so. –  Mar 09 '18 at 20:18
  • cool, any ideas how it could work ? I assume some loaders have to be changed for it – user7646471 Mar 09 '18 at 20:22
  • Update every namespace referencing `App\Http\Controllers`, `App\Models`, etc. to your desired structure. –  Mar 09 '18 at 20:24
  • I feel that won't work . e.g routes don't have a namespace, how would it target the correct controller ? – user7646471 Mar 09 '18 at 20:28
  • Adding to the structure is probably better than trying to reinvent it. I.e. having an `app\Http\Controllers` parallel to `app\MyComponent\Http\Controllers` would be a logical approach if you want Controllers for an individual component. That being said, it could also live in `app\Http\Controllers\MyComponent`, so there's many ways to approach this. – Tim Lewis Mar 09 '18 at 20:28
  • It's entirely possible, with a bit of work. Here's a Laravel 4 answer that'll get you mostly there: https://stackoverflow.com/questions/18132220/laravel-4-package-or-modules/18137352#18137352 – ceejayoz Mar 09 '18 at 20:52
  • In short, yes. But, it requires some work. Check this answer too - I'm not sure what version of Laravel this is, though. https://stackoverflow.com/questions/35011096/change-laravel-directory-structure – adprocas Mar 09 '18 at 20:53
  • And this - https://laracasts.com/discuss/channels/general-discussion/how-i-can-change-laravel-directory-structure – adprocas Mar 09 '18 at 20:54
  • And also review this - https://laravel.com/docs/5.0/structure – adprocas Mar 09 '18 at 20:55
  • And this - https://laravel.com/docs/5.6/structure#the-root-app-directory – adprocas Mar 09 '18 at 20:56
  • The above links will help you understand the implications and what to consider when changing the directory structure. – adprocas Mar 09 '18 at 20:56
  • cool thanks. those links are helpful! – user7646471 Mar 10 '18 at 10:36

1 Answers1

4

Yes you can, actually we already did what you're thinking. We create a separate Folder and inside of it Models, Controllers, Requests , Views, Routes You just need to update the RouteProviders to rellocate your Controllers by modifying the namespace and for the Views. you just need to update via config folder .

Kenneth Sunday
  • 865
  • 7
  • 14