相关疑难解决方法(0)

如何显示在MySQL上执行的最后查询?

是否有任何查询/方式显示在所有服务器上执行的最后查询?

mysql logging

449
推荐指数
6
解决办法
44万
查看次数

如何在Laravel 5中执行查询?DB :: getQueryLog()返回空数组

我正在尝试查看查询的日志,但DB::getQueryLog()只是返回一个空数组:

$user = User::find(5);
print_r(DB::getQueryLog());
Run Code Online (Sandbox Code Playgroud)

结果

Array
(
)
Run Code Online (Sandbox Code Playgroud)

如何查看此查询的日志?

php logging laravel laravel-5

161
推荐指数
7
解决办法
22万
查看次数

Laravel 在单个子句中使用多个 where 和 sum

在我的数据库中,我有instagram_actions_histories一个表,其中有action_type一个列,在该列中我有不同的数据,例如123

例如,我正在尝试获取此表数据的关系并对存储在列中的值求和

$userAddedPagesList = auth()->user()->instagramPages()->with([
        'history' => function ($query)  {
            $query->select(['action_type as count'])->whereActionType(1)->sum('action_type');
        }
    ]
)->get();
Run Code Online (Sandbox Code Playgroud)

顺便说一句,这段代码不正确,因为我想获得其中history包含多个的所有内容sum

whereActionType(1)->sum('action_type')
whereActionType(2)->sum('action_type')
whereActionType(3)->sum('action_type')
Run Code Online (Sandbox Code Playgroud)

例如(伪代码):

$userAddedPagesList = auth()->user()->instagramPages()->with([
        'history' => function ($query)  {
            $query->select(['action_type as like'])->whereActionType(1)->sum('action_type');
            $query->select(['action_type as follow'])->whereActionType(2)->sum('action_type');
            $query->select(['action_type as unfollow'])->whereActionType(3)->sum('action_type');
        }
    ]
)->get();
Run Code Online (Sandbox Code Playgroud)

更新

$userAddedPagesList = auth()->user()->instagramPages()->with([
        'history' => function ($query) {
            $query->select('*')
                ->selectSub(function ($query) {
                    return $query->selectRaw('SUM(action_type)')
                        ->where('action_type', '=', '1');
                }, 'like')
                ->selectSub(function ($query) {
                    return $query->selectRaw('SUM(action_type)')
                        ->where('action_type', …
Run Code Online (Sandbox Code Playgroud)

php laravel laravel-5.6

3
推荐指数
1
解决办法
5157
查看次数

标签 统计

laravel ×2

logging ×2

php ×2

laravel-5 ×1

laravel-5.6 ×1

mysql ×1