Laravel 4 和调试栏 - 显示 pdo 查询


Laravel 4 and debugbar - show pdo queries?

我已经安装了:https://github.com/barryvdh/laravel-debugbar 使用作曲家。

我按照安装过程进行操作,现在完成了。

但是如何查看我的 PDO mysql 查询?我正在构建一个RESTful api,没有任何HTML/视图渲染。

不知道它是否有任何用途,但这是我的代码的一些示例:

    // the controller
    public function feed($exclude = null) {
        $feed = $this->item->feed()->with('attributes', 'images', 'user');
        if($exclude)
            $feed->whereNotIn('id', explode(',', $exclude));
        return ['items' => $this->itemTransformer->transformCollection($feed->get()->toArray())]; // woud like to debug this query
    }
    // the router
    Route::get('items/feed/{exclude?}', ['protected' => true, 'uses' => 'ItemsController@feed']);

调试栏应在启用时记录所有请求,即使未输出 HTML 也是如此。您可以尝试创建 1 个简单的 HTML 页面,以便呈现调试栏。您可以单击"浏览"按钮(右侧的关闭按钮旁边)来浏览以前的请求。您应该获得一个包含已收集请求的列表,您可以按 url/ip/method 进行过滤。单击该按钮将在调试栏上显示该信息。

简单:

    public function feed($exclude = null) {
        $feed = $this->item->feed()->with('attributes', 'images', 'user');
        if($exclude)
            $feed->whereNotIn('id', explode(',', $exclude));
        $items = ['items' => $this->itemTransformer->transformCollection($feed->get()->toArray())];
        echo json_encode($items); // echo instead of return. Will trigger HTML to render and
    }