Remove
count()
and then in your view
{{count($numberoftwits)}}
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Snippet in the controller
$numberoftwits = DB::table('twits')
->groupBy('user_id')
->count()
->get();
mysql query
SELECT COUNT(*) FROM twits GROUP BY user_id
Error Call to a member function get() on integer
What should I do in order to pass the result of the query to the compact statement in the controller?
both solutions didnt not work however I was able to solve the problem by using db raw
$numberoftwits = DB::table('twits')
->select(DB::raw('count(*) as num'))
->groupBy('user_ID')
->get();
Please or to participate in this conversation.