使用laravel db,listen无效

badman

参考了此帖子的回答,https://www.workerman.net/q/7727
并未解决问题,确定是有调用对应的start方法,但是就是监听不到sql语句。如下图
环境(vagrant homestead)

控制器代码

<?php
namespace app\controller;

use app\model\Order;
use Illuminate\Database\QueryException;
use support\Db;
use support\Request;

class User
{
    public function index(Request $request)
    {
//        $data = Order::filter($request->all())->get();
//        $data = Order::where('id',1)->first();
        $data = Db::table('cz_order')->where('id','>',1)->first();
        return json($data);
    }
}

app/bootstrap/Report.php

<?php
namespace app\bootstrap;
use support\Db;
use Webman\Bootstrap;

class Report implements Bootstrap
{
    public static function start($worker)
    {
        echo "Report start被调用啦~\n";
        Db::listen(function(\Illuminate\Database\Events\QueryExecuted $query) {
            echo $query->sql. "\n";
        });
    }
}

config/bootstrap.php

<?php
return [
    support\bootstrap\Session::class,
    support\bootstrap\LaravelDb::class,
    \app\bootstrap\Report::class,
];
阅读 104
1个回答

walkor

执行 composer require illuminate/events,然后restart重启试下

  • badman 7天前

    感谢老大的耐心解答,解决了。