简体   繁体   中英

Where does one place Models in a Laravel Package?

I'm currently following the Laravel Package documentation, which uses the workbench tool to create a standard package tree consisting of controller , config , views , etc. folders. Basically, most folders you would get in a standard Laravel app tree.

However, I had a couple of questions:

  • Why is the models folder absent here? (though the same goes for tests and commands )
  • Should I just create the folder myself and add it to the composer.json autoload classmap?
  • What classes should live inside src/<Namespace>/<PackageName> ? I have noticed that a ServiceProvider is automatically created here, but I can imagine most other files just existing in the standard package directories.

Wockbench represents just a tool for creating other tools, that is triggered through CLI. Workbench is very abstract concept.

Model folder is absent simply because you don't need model in every new package. For example, if you are creating middleware package or you own filter package.

Every new class can be added to package dependent on its purpose and responsibility. It can be done in more then one way.

Classes that are general enough to go into every package are:

Package Service Provider
Facade
Basic Class 

But it is not a black box. Consider for example request class - it is bound very early in the application life cycle, so no provider is needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM