Answer the question
In order to leave comments, you need to log in
How to display queries to the database on the screen in laravel?
I watch lessons and there at the teacher the dump () function issues queries to the database on the screen. But I only have data. Can you please tell me how to enable this feature?
Answer the question
In order to leave comments, you need to log in
Knee variant
For specific request
<?php
DB::enableQueryLog();
//Ваш код .....
$dump = DB::getQueryLog();
$bindings = $dump[0]['bindings'];
$query = $dump[0]['query'];
$query = str_replace('?','"?"',$query);
dump(str_replace_array('?',$bindings,$query));
//AppServiceProvider.php
<?php
//....
public function boot() {
DB::listen(function($query) {
$bindings = $query->bindings;
$sql = $query->sql;
$sql = str_replace('?','"?"',$sql);
dump(str_replace_array( '?', $bindings, $sql)."{$query->time} sec");
});
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question