Visitar URL original
How to write to the log using DB::listen() ? · Issue #197 · mattstauffer/Torch · GitHub
Skip to content

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

Open

Description

@asundust

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

Activity

  1. lwohlhart commented on Aug 19, 2022

    @lwohlhart

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions