【问题标题】:Capturing rows affected by query with Event使用 Event 捕获受查询影响的行
【发布时间】:2017-12-14 08:41:38
【问题描述】:

我正在尝试编写一个事件来显示有多少行受到查询的影响。

我找到了 Illuminate\Database\Events\QueryExecuted 事件。我已经为事件添加了一个监听器并在事件服务提供者中注册了它:

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);
            //
        }

}

在我的处理方法中,我可以看到正在运行的查询:

public function handle(QueryExecuted $event)
        {

            var_dump($event);

        }

但是,我找不到查看查询运行更新/删除了多少行的方法。

如果有任何建议,我将不胜感激。

【问题讨论】:

    标签: php mysql laravel laravel-5 laravel-events


    【解决方案1】:

    你的 Laravel 应用程序中包含的 EventServiceProvider 提供了一个方便的地方来注册你的应用程序的所有事件监听器。

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

    【讨论】:

    • 谢谢,但这不是问题所在。我已经成功注册了一个事件监听器。
    猜你喜欢
    • 1970-01-01
    • 2021-09-14
    • 2013-02-16
    • 1970-01-01
    • 2019-05-17
    • 1970-01-01
    • 1970-01-01
    • 2018-06-10
    • 2018-05-13
    相关资源
    最近更新 更多