2

I am developing web base application using Laravel 5.6 . There are many database queries to execute.

As a security purpose I try to store my all queries into a database table as Query log. I have uses AppServiceProvider service provider to do that. Now I want to disable Query_Log() function for a while that prevent storing particular database query also. when I run app with above code, It was running while exceeding database maximum execution time.

Can somebody suggest me how I do that?

public function boot()
{
    if(env('App_Debug')){

        DB::listen(function($query){

           //DB::connection()->disableQueryLog();
            Query_Log::insert([
                'query_string'=>$query->sql,
                'user' => "Admin",
                'created_at' =>Carbon::now()->toDateTimeString(),
            ]);   
        });
    }
}
Pushpamal
  • 107
  • 2
  • 16

1 Answers1

0

This is how i exclude the listener. i don't know if there is existing function

    DB::listen(function ($query) {
        try {
            //check if the query log is the excluded table
            if (preg_match('(query_activities)', $query->sql) == 0) {
                QueryActivity::query()->create([
                    'connection_name' => $query->connectionName,
                    'time_taken' => $query->time,
                    'query' => $query->query,
                    'bindings' => Utils::aesEncrypt(json_encode($query->bindings)),
                ]);
            }
        } catch (\Exception $exception) {

        }
    });
ZeroOne
  • 8,996
  • 4
  • 27
  • 45