原文地址 https://www.workerman.net/q/7790 # 使用laravel db,listen无效 [![](https://www.workerman.net/avatar.png)**badman**](https://www.workerman.net/u/badman)10天前 参考了此帖子的回答,[https://www.workerman.net/q/7727](https://www.workerman.net/q/7727) 并未解决问题,确定是有调用对应的start方法,但是就是监听不到sql语句。如下图 环境(vagrant homestead) ![](https://www.workerman.net/upload/img/20220114/1461e0f173cd2d.png) 控制器代码 ~~~php <?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 <?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 <?php return [ support\bootstrap\Session::class, support\bootstrap\LaravelDb::class, \app\bootstrap\Report::class, ]; ~~~ 执行`composer require illuminate/events`,然后restart重启试下