mardi 9 mai 2017

How to add count to a eloquent array?

In my webshop i have searchgroups and searchtags.

Every searchtag belongs to a searchgroup.

The searchtags are connected to bikegroups with a many-to-many relation.

DB: enter image description here

How i retrieve my groups with tags:

$searchgroups = SearchGroup::with('searchtags')->get();

Now i want to count how many times each searchtag exists in tags_bike_groups and display it.

enter image description here

So that i can display:

Year

2016 (2)

2017 (5)

2018 (0)

How do i achieve this?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire