如何在laravel 5中显示最后一个查询?

时间:2016-01-03 09:06:10

标签: laravel laravel-5

我用:

DB::connection()->enableQueryLog();
var_dump(DB::getQueryLog());

但它没有用。

我的服务是这样的:

public function dataCustomerList($param) 
    {
        $status = $param['status_sort'];
        $gender = $param['gender'];
        $published = $param['published'];

        if($published=='NO'){
            $published_check = 'NO';
            $published = 0;
        }
        else if($published=='YES'){
            $published_check = 'YES';
            $published = 1;
        }
 DB::connection()->enableQueryLog();
        $customer = customer::paginate(10);

        if(!empty($status)) {
            // die($status);
            $customer = customer::where('tb_customer.customer_status', '=', $status)->paginate(10);
        }

        if (!empty($gender)) {
            $customer = customer::where('tb_customer.gender', '=', $gender)->paginate(10);
        }

        if (!empty($published_check)) {
            $customer = customer::where('tb_customer.published', '=', $published)->paginate(10);
        }
        var_dump(DB::getQueryLog());
        return $customer;


    }   

当我运行它时,查询不会出现

结果如下:

array(0) {
}

如何在Laravel 5中执行查询?

非常感谢

1 个答案:

答案 0 :(得分:3)

你可以听query events on DB

DB::listen(function($sql, $bindings, $time) {
    var_dump($sql);
});