LoginSignup
1
3

More than 5 years have passed since last update.

【Laravel】実行されたSQLを取得する

Posted at

実行されたSQLを出力します。
SQLだけでなく、プリペアドステートメントや実行時間も出力されるので便利です。

Laravel 5.0 データベースの基本的な使用法

ログの出力

// ログを有効化
DB::enableQueryLog();

City::where('Name', '=', 'Kabul')->get();

// ログ出力
dd(DB::getQueryLog());

// ログを無効化
DB::disableQueryLog();

出力結果

array:1 [
  0 => array:3 [
    "query" => "select * from `city` where `Name` = ?"
    "bindings" => array:1 [
      0 => "Kabul"
    ]
    "time" => 6.46
  ]
]
1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3