'How to convert this SQL into laravel query builder with eloquent?

How to convert this SQL to Laravel query builder using eloquent? I want to display categories table on my datatable with count(questions) on it.

SELECT questions.categories_id, count(questions.categories_id) as pertanyaan, categories.name as cat_name
    FROM questions, categories
    WHERE questions.categories_id=categories.id
    GROUP BY questions.categories_id


Solution 1:[1]

Question::join('categories','categories.id','=','questions.categories_id')
       ->groupBy('questions.categories_id')
       ->select(
             'questions.categories_id',
             'categories.name as cat_name',
             DB::raw('COUNT(questions.categories_id)')
        );
                

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 amirhosein hadi