laravel 如何读取 app/config/app.php 调试变量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32189725/
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 12:14:52  来源:igfitidea点击:

laravel how to read app/config/app.php debug variable

phplaravellaravel-4laravel-5

提问by Phil

How do I access the debug variable in app/config/app.phpfrom my controller to see if I am in debug mode?

如何app/config/app.php从控制器访问调试变量以查看我是否处于调试模式?

<?php                                                                                                                
                                                                                                                     |
  /*                                                                                                                 |        if ( $this->user->id )
  |--------------------------------------------------------------------------                                        |        {
  | Application Debug Mode                                                                                           |            // Save roles. Handles updating.
  |--------------------------------------------------------------------------                                        |            $this->user->saveRoles(Input::get( 'roles' ));
  |                                                                                                                  |
  | When your application is in debug mode, detailed error messages with                                             |            // Redirect to the new user page
  | stack traces will be shown on every error that occurs within your                                                |            return Redirect::to('admin/users/'.$this->user->id)->with('success', Lang::get('admin/users/messages.cre
  | application. If disabled, a simple generic error page is shown.                                                  |ate.success'));
  |                                                                                                                  |        }
  */                                                                                                                 |  else
                                                                                                                     |  {
  'debug' => true,    

回答by Mihail Burduja

You can use the helper function config (Laravel 5+).

您可以使用辅助函数配置(Laravel 5+)。

$debug = config('app.debug');

Laravel 4.2:

Laravel 4.2:

$debug = Config::get('app.debug');

回答by Shota

This question already has right answer, I just wanted to add that doing it with environmental variables is a better option:

这个问题已经有了正确的答案,我只想补充一点,使用环境变量来做是一个更好的选择:

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

In .env file:

在 .env 文件中:

APP_ENV=local