[Laravel] LAMP+Laravel 學習筆記-Debug

本篇介紹使用laravel 套件debugbar的四個步驟

1.安裝debugbar
2.註冊debugbar
3.啟動debugbar
4.debugbar設定

重要指令: php artisan vendor:publish


   







 


1.安裝debugbar
方便偵錯,尤其是使用ORM(Elequent)後,想要知道raw sql指令,或一些變數的傳遞
安裝方式:
$project>composer require barryvdh/laravel-debugbar --dev  #只在開發環境執行

2.註冊debugbar
修改: /app/Providers/AppServiceProvider.php
只有環境在testing or local 才註冊

     public function register()
    {
        if ($this->app->environment('local', 'testing')) {
        	  //TDD package
            $this->app->register(DuskServiceProvider::class);                
            //Debugbar package
            $this->app->register('Barryvdh\Debugbar\ServiceProvider');     
        }
    }

3.啟動debugbar
設定/env
APP_ENV=local   # local or testing   依照#2的定義
APP_DEBUG=true  #

4.debugbar設定
php artisan vendor:publish                           #同時也會將所有的套件config都一併copy到/config
將vendor/barryvdh/larave-debugbar/config/debugbar.php
copy到/config/debugbar.php        

直接修改debugbar.php內的偵錯參數
e.g 
參數:DEBUGBAR_ENABLED 預設null,可改為true/false  此參數複寫env內的APP_DEBUG

'enabled' => env('DEBUGBAR_ENABLED', true),

設定開啟的資訊
e.g db or auth....

 'collectors' => [
        'phpinfo'         => true,  // Php version
        'messages'        => true,  // Messages
        'time'            => true,  // Time Datalogger
        'memory'          => true,  // Memory usage
        'exceptions'      => true,  // Exception displayer
        'log'             => true,  // Logs from Monolog (merged in messages if enabled)
        'db'              => true,  // Show database (PDO) queries and bindings
        'views'           => true,  // Views with their data
        'route'           => true,  // Current route information
        'auth'            => true, // Display Laravel authentication status
        'gate'            => true, // Display Laravel Gate checks
        'session'         => true,  // Display session data
        'symfony_request' => true,  // Only one can be enabled..
        'mail'            => true,  // Catch mail messages
        'laravel'         => true, // Laravel version and environment
        'events'          => false, // All events fired
        'default_request' => false, // Regular or special Symfony request logger
        'logs'            => false, // Add the latest log messages
        'files'           => false, // Show the included files
        'config'          => false, // Display config settings
    ],


參考:

http://oomusou.io/laravel/laravel-debugbar/