Laravel 5.8 のdebugbarの導入
Laravelのデバッグバーを表示させたいと思います。
デバッグバーってどんなやつ?
こんなやつ。開発した画面の下部に表示してくれます。
ブラウザに描画されるまで時間や発行されているquery一覧の表示をしてくれます。
N+1問題やパフォーマンス改善をする場合などには欠かせないですね。
Composerからインストール
まずはComposerからインストールする必要があるので以下コマンドを実行してください。
$ composer require barryvdh/laravel-debugbar
もしメモリーが足りないなどのエラーが出た場合は、以下コマンドで実施してください。
php -d memory_limit=-1 `which composer` require barryvdh/laravel-debugbar
php -d をつけるとコマンド実行時の設定ディレクティブを変更することができます↓
https://www.php.net/manual/ja/features.commandline.options.php
デバッグバーの設定ファイルを生成
次にデバッグバーの設定ファイルを生成します
php artisan vendor:publish --provider="Barryvdh\Debugbar\ServiceProvider"
これを実行するとプロジェクトのconfig配下にdebugbar.phpが生成されます。
debugbar.phpを開き、envの第二引数を true としましょう
/* |-------------------------------------------------------------------------- | Debugbar Settings |-------------------------------------------------------------------------- | | Debugbar is enabled by default, when debug is set to true in app.php. | You can override the value by setting enable to true or false instead of null. | | You can provide an array of URI's that must be ignored (eg. 'api/*') | */ 'enabled' => env('DEBUGBAR_ENABLED', true), 'except' => [ 'telescope*' ],
ちなみにデフォルトだとnullが設定されているかと思いますが、nullは.envのAPP_DEBUGの設定によって表示するかどうかが変わります。
確認
仮想環境を起動した状態で導入した場合は、一度仮想環境の再起動を行いviewの表示を行うとデバッグバーが表示されていると思います。