Laravel-未调用AppServiceProvider [英] Laravel - AppServiceProvider is not called

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

问题描述

我试图在Laravel AppServiceProvider中绑定某些服务,但未绑定这些服务.我认为,甚至没有调用AppServiceProvider.其实,我做了一个新的,就可以了.

I tried to bind some services in the Laravel AppServiceProvider, but the services weren't bound. I think, that the AppServiceProvider was not even called. Actually, I made a new one and it works.

所以我的问题是,我做错了什么吗?还是没有调用AppServiceProvider?

So my question is, am I doing something wrong? Or was the AppServiceProvider not called?

推荐答案

Laravel 预编译基本上用于每个请求的某些类.这用于性能优化的目的.可以在 files 下的 config/compile.php 中指定要编译的文件.默认值如下:

Laravel pre-compiles certain classes that are used on basically every request. This serves the purpose of performance optimization. Files to compile can be specified in config/compile.php under files. The default one looks like this:

'files' => [
    realpath(__DIR__.'/../app/Providers/AppServiceProvider.php'),
    realpath(__DIR__.'/../app/Providers/BusServiceProvider.php'),
    realpath(__DIR__.'/../app/Providers/ConfigServiceProvider.php'),
    realpath(__DIR__.'/../app/Providers/EventServiceProvider.php'),
    realpath(__DIR__.'/../app/Providers/RouteServiceProvider.php'),
],

在运行 php artisan Optimization 时,如果未启用调试(或使用-force 选项),则列出的那些文件和其他框架类将被写入storage/framework/compiled.php .

When running php artisan optimize when debugging is not enabled (or with the --force option) Those listed files and other framework classes will be written to storage/framework/compiled.php.

这意味着,如果您更改了这些预编译的文件之一,则更改将不会立即应用(如果存在 compiled.php 的话),而只有在运行 php artisan优化之后再次或在运行 php artisan clear-compiled 以清除 compiled.php 文件之后.

That means if you change one of those precompiled files, changes won't be applied immediately (if compiled.php exists) but only after you run php artisan optimize again or after you run php artisan clear-compiled to clear the compiled.php file.

当然,您也可以从列表中删除 AppServiceProvider 作为替代解决方案.

Of course you can also remove the AppServiceProvider from the list as an alternative solution.

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

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