Here’s a way to assess the performance of a query:
-
-
- Start tinker in the Laravel project directory
php artisan tinker
- Start DB::listen
DB::listen(function ($query) { dump($query->sql); dump($query->bindings); dump($query->time); });
- Issue query. Here’s an example:
$query=UserLog::where([\ ['user_id', '=', 'AAABBBCCC000111222'],\ ['user_name', '<>', null],\ ])\ ->select('user_id', 'user_address', 'user_phone_number','created_at')\ ->get();
- Start tinker in the Laravel project directory
- You will see the SQL statement being executed, list of binding parameters and execution time
"select `user_id`, `user_address`, `user_phone_number`,`created_at`, from `user_logs` where (`user_id` = ? and `user_name` is not null)" array:1 [ 0 => "AAABBBCCC000111222" ] 142.74
-