kaizokupuffball
2 weeks ago

Call to a member function pluck() on a non-object

Posted 2 weeks ago by kaizokupuffball

Hi

I have this query in the controller.

$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(); 

Based on that, I am getting this output-

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

]

Now, I'm trying to use the following to extract only the user_ids :

$top_ids = $top_cont->pluck('user_id'); 

But getting this error-

Call to a member function pluck() on a non-object

Any idea why?

Please sign in or create an account to participate in this conversation.