Change laravel directory structure

懵懂的女人 提交于 2019-12-11 12:55:58

问题


atm i'm beginning to develop a big application and the current structure of laravel just doesn't fit what i had in thought. The controllers, models and views are all in seperate folders just bunched up and things could get messy when there's loads of them.

So I was hoping I could change the default way laravel loads it's controllers views and models. My approach would be something like this:

-App
--Content
---Login
----Controller
----Model
----View
----Js
---Home
----Controller
----Model
----View
----Js
--BaseContent
---BaseLayout
---BaseController
---BaseJS

So when the route is home the controller model view and javascript all get bundled in a folder instead of having all of it in one controller directory, model directory, view directory etc.

So my question is does someone know how I could change the way laravel load's it's dependency's? I'm kinda hoping for a configuration file I just can't seem to find.


回答1:


I understand your thoughts. You want to group by feature.

It's possible. All you need are namespaces conform PSR-4. In composer.json you can link/specify the namespaces and paths, for example, you have in your controller this line:

namespace App\Http\Controllers;

In composer.json see the following fragment in autoload:

"psr-4": {
    "App\\": "app/"
}

The namespace App refers to the directory app, and all classes with the namespace beginning with App\ will be autoloaded. So it's simple for your to change the directory structure.



来源:https://stackoverflow.com/questions/35011096/change-laravel-directory-structure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!