Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无法从Laravel中的查询结果中提取列_Php_Laravel - Fatal编程技术网

Php 无法从Laravel中的查询结果中提取列

Php 无法从Laravel中的查询结果中提取列,php,laravel,Php,Laravel,我有以下问题想问一下前5名出资人: $top_cont = DB::table('quests') ->select('user_id', DB::raw('count(*) as contributions')) ->whereDate('created_at', '>=', now()->startOfDay()) ->take(5) ->groupBy('user_id') ->orderBy('cont

我有以下问题想问一下前5名出资人:

$top_cont = DB::table('quests') 
    ->select('user_id', DB::raw('count(*) as contributions'))
    ->whereDate('created_at', '>=', now()->startOfDay()) 
    ->take(5)
    ->groupBy('user_id')
    ->orderBy('contributions', 'desc')
    ->get(); 
以下是阵列输出:

array:2 [▼
  0 => {#379 ▼
    +"user_id": 2
    +"contributions": 2
  }
  1 => {#380 ▼
    +"user_id": 8
    +"contributions": 1
  }

]
我试图使用以下内容仅提取
用户id
s:

$top_ids = $top_cont->pluck('user_id'); 
但有以下错误:

对非对象调用成员函数pull()


如果你有数组,那么你可以使用

$array = [...];
$userIds = collect($array)->pluck('user_id');