xxxxxxxxxx
namespace App\Providers;
use DB;
use Log;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
DB::listen(function($query) {
Log::info(
$query->sql,
$query->bindings,
$query->time
);
});
}
// ...
}
xxxxxxxxxx
DB::enableQueryLog();
$arr_user = DB::table('users')->select('name', 'email as user_email')->get();
dd(DB::getQueryLog());
xxxxxxxxxx
DB::connection()->enableQueryLog(); //enable query log
$data = $order->all(); //query execute
$queries = DB::getQueryLog(); //get query
return dd($queries); //show query
xxxxxxxxxx
DB::enableQueryLog();
$user = DB::table('users')->select('name', 'email as user_email')->get();
dd(DB::getQueryLog());
xxxxxxxxxx
check whethe the serviceprovider is added in the providers array in config/app.php
if no then check whether the service provider class is the correct location and
include the serivce provider in the providers array in config.app.php
xxxxxxxxxx
public function show(Order $order){
\DB::connection()->enableQueryLog();
$data = $order->all();
$queries = \DB::getQueryLog();
return dd($queries);
}
xxxxxxxxxx
check whethe the serviceprovider is added in the providers array in config/app.php
if no then check whether the service provider class is the correct location and
include the serivce provider in the providers array in config.app.php