I
I
Ivan Lykov2018-03-05 16:16:24
Laravel
Ivan Lykov, 2018-03-05 16:16:24

How to find out how many posts are stored in a category?

Good time, question.
There are let's say 5 categories, in each category there are entries in a different number.
How to make it so that under each category you can see how many records it currently stores in itself Like
this:
Category_1 (29)
Category_2 (5)
Category_3 (16)
Category_4 (2)
Category_5 (96)
My categories are displayed like this right now. How else can I add the number of records they have here?

public static function getOneBlockInSidebarAdmin() {
        return = DB::table('tags')->where('id_category_sidebar', 'OneBlock')->get();
    }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Aksentiev, 2018-03-05
@Sanasol

Make queries to the database...
https://www.w3schools.com/sql/func_mysql_count.asp
https://laravel.com/docs/5.6/queries#aggregates

N
Nikolay, 2018-03-06
@iNickolay

Use Eloquent ORM for this - it will be much easier.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question