0

I am trying to write an event that will display how many rows were affected by a query.

I found the Illuminate\Database\Events\QueryExecuted Event. I have added a listener for the event and registered it in Event service Provider:

EventServiceProvider.php

<?php
namespace App\Providers;
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;


 class EventServiceProvider extends ServiceProvider
    {
        /**
         * The event listener mappings for the application.
         *
         * @var array
         */
        protected $listen = [
            'Illuminate\Database\Events\QueryExecuted' => [
            'App\Listeners\QueryExecutedListener@handle'
                ],
        ];
        /**
         * Register any other events for your application.
         *
         * @param  \Illuminate\Contracts\Events\Dispatcher  $events
         * @return void
         */
        public function boot(DispatcherContract $events)
        {
            parent::boot($events);
            //
        }

}

and in my handle method I can see the queries being run:

public function handle(QueryExecuted $event)
        {

            var_dump($event);

        }

However, I can't find a way to see how many rows were updated/deleted by the query run.

I'd appreciate any advice.

Programatt
  • 786
  • 4
  • 11
  • 23

1 Answers1

-2

The EventServiceProvider included with your Laravel application provides a convenient place to register all of your application's event listeners.

https://laravel.com/docs/5.4/events

Tejas Gami
  • 11
  • 3