我无法在生产中关闭 Laravel 中的调试栏

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46848732/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 16:50:38  来源:igfitidea点击:

I can't turn off debug bar in Laravel on production

phplaraveldebuggingproduction-environment

提问by Tutu Kaeen

I have set

我已经设定

'enabled' = false

in both package and in config/debugbar.php

在包和 config/debugbar.php 中

I cleared cache with

我清除了缓存

php artisan cache:clear

but I still see it on production environment. I accidently commited

但我仍然在生产环境中看到它。我不小心犯了

'enabled' = false

by accident and can't turn it off. I even rolled back commits, but that doesn't help. Any ideas?

不小心,无法关闭。我什至回滚了提交,但这无济于事。有任何想法吗?

@edit the .env has also debug set to false

@edit .env 也调试设置为 false

@edit2 also when I got ot /login route on new browser (or private mode) I don't see the bar, but when I refresh this page, it is there again

@edit2 也是当我在新浏览器(或私有模式)上获得 ot /login 路由时,我看不到栏,但是当我刷新此页面时,它又出现了

采纳答案by Alexey Mezenin

Solution for 5.5 and above

5.5及以上解决方案

Install the package with:

安装包:

composer require barryvdh/laravel-debugbar:dev-master

Because of the package auto-discovery feature, you don't need to add package's service provider to the providerslist in config/app.phpand Debugbar will only be loaded in the development environment.

由于包自动发现功能,您不需要将包的服务提供者添加到providers列表中config/app.php,Debugbar 只会在开发环境中加载。

Solution for 5.4 and below

5.4及以下的解决方案

Put this code to the AppServiceProvider@register:

将此代码放入AppServiceProvider@register

if ($this->app->isLocal()) {
    $this->app->register('Barryvdh\Debugbar\ServiceProvider');
}

Don't forget to remove Laravel Debugbar line from config/app.phpproviders section.

不要忘记从config/app.phpproviders 部分中删除 Laravel Debugbar 行。

After doing this, Laravel Debugbar will only be loaded in a local environment.

这样做之后,Laravel Debugbar 将只会在本地环境中加载。

回答by Yevgeniy Afanasyev

It is not a matter of debugbar, it is general problem with .env. You can change your APP_NAME to see it is not changing anything.

这不是调试栏的问题,而是 .env 的普遍问题。您可以更改您的 APP_NAME 以查看它没有改变任何内容。

To apply your new config changes including .env changes you need to run artisan command in your project folder:

要应用包括 .env 更改在内的新配置更改,您需要在项目文件夹中运行 artisan 命令:

php artisan config:cache

回答by Riyaz

did u try changing it in the .env file.

你有没有尝试在 .env 文件中更改它。

look for the value APP_DEBUG in the .env file and set it false.

在 .env 文件中查找值 APP_DEBUG 并将其设置为 false。

Out of the box, .env has it set to true.

开箱即用,.env 将其设置为 true。

回答by Carlos Sanchez

if you are on 5.4 you can do under AppServiceProvider as follows:

如果您使用的是 5.4,您可以在 AppServiceProvider 下进行如下操作:

public function register()
{
/*
 * Sets third party service providers that are only needed on local/testing environments
 */
if ($this->app->environment() != 'production') {
/**
 * Loader for registering facades.
 */
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
/*
 * Load third party local aliases
 */
$loader->alias('Debugbar', \Barryvdh\Debugbar\Facade::class);
}
}

if you want full control under 5.5 you can do in the same AppServiceProvider:

如果你想在 5.5 下完全控制你可以在同一个 AppServiceProvider 中做:

public function register()
{
    /*
     * Sets third party service providers that are only needed on local/testing environments
     */
    if ($this->app->environment() != 'production') {
        /**
         * Loader for registering facades.
         */
        $loader = \Illuminate\Foundation\AliasLoader::getInstance();

        /*
         * Load third party local providers
         */
        $this->app->register(\Barryvdh\Debugbar\ServiceProvider::class);

        /*
         * Load third party local aliases
         */
        $loader->alias('Debugbar', \Barryvdh\Debugbar\Facade::class);
    }
}

and under composer.json in the extra:

并在额外的 composer.json 下:

"extra": {
    "laravel": {
        "dont-discover": [
            "barryvdh/laravel-debugbar"
        ]
    }
},

Then you are good to go and enable and disable via .env, if it's different of production it will be enabled (local, testing, etc..) if it's on production it will be automatically disabled.

然后你可以通过 .env 启用和禁用,如果它与生产不同,它将被启用(本地、测试等),如果它在生产中,它将被自动禁用。

Hope it helps, good luck!

希望能帮到你,祝你好运!