javascript - Count value db Laravel

Solution:

What you are looking for is called a group by, I have added a sample query below, Because without proper table description and exact output requirement its hard to provide a correct answer, But the following should give you a direction.

$itemsCount = DB::table('items')
->groupby('level_id')
->selectRaw('level_id, count(*) as apartment_count');

you should be able to get an output similar to the following

+

Answer

+

Answer

-------+ | level_id | apartment_count | +

Answer

+

Answer

-------+ | 0 | 1 | | 1 | 10 | | 2 | 4 | +

Answer

+

Answer

-------+

Source