[英]Capturing rows affected by query with Event
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. 我找到了Illuminate \\ Database \\ Events \\ QueryExecuted事件。 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: 在我的handle方法中,我可以看到正在运行的查询:
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. 我将不胜感激任何建议。
The EventServiceProvider included with your Laravel application provides a convenient place to register all of your application's event listeners. Laravel应用程序附带的EventServiceProvider提供了一个方便的位置来注册应用程序的所有事件侦听器。
https://laravel.com/docs/5.4/events https://laravel.com/docs/5.4/events
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.