Laravel 文件夹结构 [英] Laravel folder structures

查看:38
本文介绍了Laravel 文件夹结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在决定将文件夹放在 app\ 文件夹内的资源的位置时,我经常发现它有问题.

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

我应该在哪里放置诸如模型观察者validatorsform macrosrepositories之类的东西.... 目前我执行以下操作

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
         \...

我不明白 \Acme 文件夹背后的原因,因为它与实际应用程序相同?

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

推荐答案

掌握 Laravel 文件夹结构的最佳方法是将 app 目录视为框架的前端.如果您查看 git 存储库,您会发现它们是分开的 - 您可以克隆核心库,然后可以单独克隆 Laravel 应用程序.应用程序及其子文件夹仅代表可以使用框架的一种方式.当然,它的设计涉及最佳实践.还可以查看核心框架 tests 目录——那里 Laravel 开发人员将库视为无头"——没有应用程序.对我来说,这就是我掌握 Laravel 所需的一切.

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.

因此您可以自由修改现有结构,但请记住,某些更改需要您composer dump-autoload - 主要是因为命名空间.

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.

这篇关于Laravel 文件夹结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆