Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to write to the log using DB::listen() ? #197

Open
asundust opened this issue Nov 3, 2021 · 1 comment
Open

How to write to the log using DB::listen() ? #197

asundust opened this issue Nov 3, 2021 · 1 comment

Comments

@asundust
Copy link

asundust commented Nov 3, 2021

How to write to the log using DB::listen() ?

@lwohlhart
Copy link

lwohlhart commented Aug 19, 2022

Hey, I just ran into the same question:

If you have registered an EventDispatcher on the Capsule Manager you can register an event listener:

$eventDispatcher = new Dispatcher(new Container);
$capsule->setEventDispatcher($eventDispatcher);

# or alternatively if the capsule is defined already
$eventDispatcher = $capsule->getEventDispatcher();

$eventDispatcher->listen(\Illuminate\Database\Events\QueryExecuted::class,
    function (\Illuminate\Database\Events\QueryExecuted $query)  {
        // $query->sql;
        // $query->bindings;
        // $query->time;
    }
);

hth

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants