简体   繁体   English

Laravel 5. 调试模式

[英]Laravel 5. Debug mode

I set debug mode to true in config->app and deployed it on the server:我在 config->app 中将调试模式设置为true并将其部署在服务器上:

'debug' => env('APP_DEBUG', true),

I have following code in Controller to check the mode:我在控制器中有以下代码来检查模式:

...
$debug = config('app.debug');
var_dump($debug);
$product->save();

Result on local machine:本地机器上的结果:

C:\\xampp\\htdocs\\MK\\app\\Http\\Controllers\\ProductController.php:45:boolean true C:\\xampp\\htdocs\\MK\\app\\Http\\Controllers\\ProductController.php:45:boolean true

Result on the server:服务器上的结果:

bool(false) Whoops, looks like something went wrong. bool(false) 哎呀,好像出了点问题。

Why isn't debug mode set on server side?为什么不在服务器端设置调试模式?

This line in your config file, 'debug' => env('APP_DEBUG', true) , may be the cause of your issue.配置文件中的这一行'debug' => env('APP_DEBUG', true)可能是导致问题的原因。

It is saying;它在说; set debug to the value defined in my .env file, and if there is none then use true .debug设置为我的.env文件中定义的值,如果没有,则使用true

As such it is looking at APP_DEBUG=false in your .env file, even though you have set the second parameter to true.因此,即使您已将第二个参数设置为 true,它也会查看.env文件中的APP_DEBUG=false

Try updating the setting in your .env file to true.尝试将.env文件中的设置更新为 true。

First of all the debug mode need to be activated!首先需要激活调试模式 And the APP_ENV need to be set to local .并且APP_ENV需要设置为local

Now how to do that!现在该怎么做! We need to check in multiple places我们需要检查多个地方

.env file .env 文件

APP_ENV=local
APP_DEBUG=true

Make sure they are not set twice!确保它们没有设置两次! You can Uncomment with # APP_ENV=production (using # ).您可以使用# APP_ENV=production取消注释(使用# )。

Too importantly you need to change APP_ENV to local .太重要了,您需要将APP_ENV更改为local

And to check, you can run并检查,你可以运行

php artisan env

You get something like:你会得到类似的东西:

在此处输入图片说明

config/app.php配置/app.php

Next thing to check is config/app.php接下来要检查的是config/app.php

Know that the .env is processed by this file!知道.env是由这个文件处理的! And that file is where the config is managed!该文件是管理配置的地方!

Check that the config line is not removed or commented !检查配置行没有被删除或注释
(depending if it's a new install or some already worked on project) (取决于它是新安装还是一些已经在项目中工作)

Depending on what version of Laravel you are using!取决于您使用的 Laravel 版本! It may be slightly different!可能略有不同!

But the point is to make sure that the .env config is loaded or it will default to true !但关键是要确保 .env 配置已加载,否则将默认为true

'debug' => env('APP_DEBUG', true) // second param the default value

In our current project!在我们当前的项目中! The setting were as bellow:设置如下:

'debug' => (function_exists('env')) ? env('APP_DEBUG', true) : true,

it check if env exists!它检查 env 是否存在! if yes it use it !如果是它使用它! If not it will set the default value directly!如果不是它会直接设置默认值!

My teammate!我的队友! Didn't notice that!没注意到! And he got an error!他犯了一个错误! Becaues somebody before us have changed it as bellow (and was commented):因为我们之前有人将其更改为如下(并被评论):

在此处输入图片说明

The image is added to illustrate how a mistake can be made!添加图像是为了说明错误是如何发生的! Also for navigation clearance!也是为了通航!

Bottom line check it out and make sure it's all right!底线检查它并确保它没问题! (if all right then just move to the next section) (如果没问题,请移至下一部分)

Ok all set but not working确定一切设置但不工作

Yea to be expected !是的,意料之中!

Clear views and cache清除视图和缓存

Importantly you should know that you may need to clear the cache重要的是您应该知道您可能需要清除缓存

Run运行

php artisan view:clear

and

php artisan cache:clear

After that it should work!之后它应该工作!

If not!如果没有!

Files permissions文件权限

You may have file system permission problems!您可能有文件系统权限问题!

Check this out看看这个

https://stackoverflow.com/a/28063794/7668448 https://stackoverflow.com/a/28063794/7668448

The expected debug view预期的调试视图

在此处输入图片说明

Laravel beautiful debug screen ❤️ Laravel 漂亮的调试画面❤️

在您的情况下,只需转到您的.env文件并将"APP_DEBUG=false"更改为"APP_DEBUG=true"

You can also change the setting into your .env file from您还可以将设置更改为您的 .env 文件

APP_ENV=production
APP_DEBUG=false

to

APP_ENV=local
APP_DEBUG=true

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

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