Skip to content

Instantly share code, notes, and snippets.

@allaniftrue
Created February 19, 2018 10:47
Show Gist options
  • Save allaniftrue/f137129a338f5ec67dc582194c58d9a4 to your computer and use it in GitHub Desktop.
Save allaniftrue/f137129a338f5ec67dc582194c58d9a4 to your computer and use it in GitHub Desktop.
How to log eloquent queries when you are using the the illuminate package outside of laravel.
<?php
$capsule = \Illuminate\Database\Capsule\Manager::connection();
$test = \App\Test::where('id', 1)->get();
error_log('SQL: ' . print_r($capsule->getQueryLog(), true));
//without the bindings
error_log('RAW SQL:' . \App\Test::where('id', 1)->toSql());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment