DB::enableQueryLog();
$arr_user = DB::table('users')->select('name', 'email as user_email')->get();
dd(DB::getQueryLog());
DB::enableQueryLog();
$user = DB::table('users')->select('name', 'email as user_email')->get();
dd(DB::getQueryLog());
Method #1
instead of ->get use ->toSql() on query
$users = User::orderBy('name', 'asc')->toSql();
echo $users;
// Outputs the string:
'select * from `users` order by `name` asc'
Method # 2
DB::enableQueryLog();
// and then you can get query log
dd(DB::getQueryLog());
use IlluminateSupportFacadesDB;
...
...
public function UserController()
{
DB::enableQueryLog();
$arr_user = DB::table('users')->select('name', 'email as user_email')->get();
dd(DB::getQueryLog());
}
public function show(Order $order){
DB::connection()->enableQueryLog();
$data = $order->all();
$queries = DB::getQueryLog();
return dd($queries);
}
namespace AppProviders;
use DB;
use Log;
use IlluminateSupportServiceProvider;
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
);
});
}
// ...
}
import DB with this line first,
use IlluminateSupportFacadesDB;
DB::connection()->enableQueryLog();
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
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
DB::listen(function ($query) {
var_dump([
$query->sql,
$query->bindings,
$query->time
]);
});