简体   繁体   English

Laravel软件包是否需要在app.php中注册服务提供商?

[英]Is registering a Service Provider in app.php required for Laravel packages?

I've built a composer package for Laravel and it uses a Service Provider. 我为Laravel构建了一个作曲家软件包,它使用了服务提供商。 I currently load it in the "providers" array in app.php after installing it to get it to work, but it seems like there should be a way to tell Composer to do that automatically to make set up easier for developers. 安装后,我目前将其加载到app.php的“ providers”数组中,以使其正常工作,但似乎应该有一种方法可以告诉Composer自动执行此操作,以使开发人员更容易进行设置。 Is that possible, or does it have to be done manually by the developer when they make a new package? 这是否可能,或者开发人员在制作新软件包时必须手动完成?

Yes, it's required that you register the Service Provider in the app config. 是的,要求您在应用程序配置中注册服务提供商。 Even if you find a way to autoload your Service Provider with Composer, it doesn't know what a Service Provider is. 即使您找到一种通过Composer自动加载服务提供商的方法,它也不知道服务提供商是什么。 You need to register it within the framework, because Laravel will handle calling your boot() and register() methods in the right order at the right time. 您需要在框架中注册它,因为Laravel将在正确的时间以正确的顺序处理调用boot()和register()方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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