Aggregation
Introduction
Aggregation combines related activities into one feed item, so three orders from one customer appear as one row. See Choosing What to Group to decide when that helps the reader.
Grouping Activities
Repeated Activities
Three orders from one customer, minutes apart, in log mode:
Define a headline with grouped() to describe them together:
use App\Models\Order;
use Storyfeed\Facades\Story;
use Storyfeed\Grouping\GroupBuilder;
Story::for(Order::class)
->verb('place')
->grouped(
fn (GroupBuilder $group) => $group
->repeat(':actor made :count order placements with :target'),
);Activities Sharing a Role
Five customers ordering from the same shop need a different sentence. Each group names an axis: what its activities have in common.
use Storyfeed\Facades\Story;
use Storyfeed\Grouping\GroupBuilder;
Story::verb('place')->grouped(
fn (GroupBuilder $group) => $group
->actorsOnTarget(':actors ordered from :target'),
);A repeat group contains one type, so its headline belongs under Story::for(Order::class) and can say "orders". An actors_target group may also contain reservations, so its headline belongs on the verb alone and must not name a type.
Storyfeed groups activities when published. Each activity belongs to only one group per read mode. A composed feed reads as Log; with live(), it groups its dated entries that have a verb.
To keep quotes and images visible individually, see Choosing What to Group. Storage Architecture shows where groups are stored and how a feed retrieves them.
Members' Featured Entities
Each activity features one role's entity, its object unless the activity says otherwise; see Featuring Another Role. A group lists the entity each member features in sample.featured, newest first, one entry per member, so an entity can repeat. For photos uploaded together, these are the photos:



[
{
"kind": "group",
"id": "grp_djIfcmVwZWF0H2IxOjc0OWMzNWU2MmY4ZjQxYjM5YzliZWZiMzYzYjE4YjM3NThlNWQ4NWM3YTM5N2I2MTUwYzZkNDlkYzBjY2Q0MGI6MDBlN3F0MW53MDAwMDAwMDAwMDAwMDAwMDE",
"axis": "repeat",
"count": 3,
"verb": "upload",
"published_at": "1985-06-30T11:05:00.000000Z",
"headline_template": ":actor uploaded :count photos to :target",
"headline": null,
"bindings": null,
"glyph": "image",
"glyph_intent": null,
"actor": {
"type": "user",
"id": "105",
"label": "Jonathan Byers",
"link": {
"href": "/users/105",
"modal": false,
"attributes": []
},
"data": [],
"media": {
"icon": null,
"image": null,
"preview": null,
"initials": "JB",
"color": "#be123c",
"files": [],
"slots": []
},
"media_ref": "m9f6d41167f25287a",
"entity_ref": "e02444442f97e8ea2",
"body": null,
"tombstone": null
},
"object": null,
"target": {
"type": "venue",
"id": "103",
"label": "the Hawkins Post",
"link": {
"href": "/venues/post",
"modal": false,
"attributes": []
},
"data": [],
"media": {
"icon": null,
"image": null,
"preview": null,
"initials": "TP",
"color": "#15803d",
"files": [],
"slots": []
},
"media_ref": "m8d99a06bd4900dc8",
"entity_ref": "e70fb65f86688b833",
"body": null,
"tombstone": null
},
"context": null,
"origin": null,
"result": null,
"instrument": null,
"location": null,
"generator": null,
"featured": null,
"sample": {
"actors": [
{
"type": "user",
"id": "105",
"label": "Jonathan Byers",
"link": {
"href": "/users/105",
"modal": false,
"attributes": []
},
"data": [],
"media": {
"icon": null,
"image": null,
"preview": null,
"initials": "JB",
"color": "#be123c",
"files": [],
"slots": []
},
"media_ref": "m9f6d41167f25287a",
"entity_ref": "e02444442f97e8ea2",
"body": null,
"tombstone": null
}
],
"objects": [
{
"type": "photo",
"id": "3103",
"label": "IMG_3103.jpg",
"link": {
"href": "/photos/3103",
"modal": false,
"attributes": []
},
"data": [],
"media": {
"icon": null,
"image": null,
"preview": {
"src": "/media/worlds/stranger-things/darkroom.jpg",
"mediaType": "image/jpeg",
"width": 960,
"height": 720,
"alt": "A room lit red"
},
"initials": "I",
"color": "#4338ca",
"files": [],
"slots": []
},
"media_ref": "m927bf2541bf27668",
"entity_ref": "ec2557674a1d80c0c",
"body": [
{
"$body": "Storyfeed/Body/Image",
"$v": 3,
"alt": "A room lit red",
"caption": "A room lit red",
"image": "preview"
}
],
"tombstone": null
},
{
"type": "photo",
"id": "3102",
"label": "IMG_3102.jpg",
"link": {
"href": "/photos/3102",
"modal": false,
"attributes": []
},
"data": [],
"media": {
"icon": null,
"image": null,
"preview": {
"src": "/media/worlds/stranger-things/arcade.jpg",
"mediaType": "image/jpeg",
"width": 960,
"height": 720,
"alt": "Arcade machines in a dark room"
},
"initials": "I",
"color": "#b45309",
"files": [],
"slots": []
},
"media_ref": "m68b47766673ac40e",
"entity_ref": "ee5d966e85f54c9e6",
"body": [
{
"$body": "Storyfeed/Body/Image",
"$v": 3,
"alt": "Arcade machines in a dark room",
"caption": "Arcade machines in a dark room",
"image": "preview"
}
],
"tombstone": null
},
{
"type": "photo",
"id": "3101",
"label": "IMG_3101.jpg",
"link": {
"href": "/photos/3101",
"modal": false,
"attributes": []
},
"data": [],
"media": {
"icon": null,
"image": null,
"preview": {
"src": "/media/worlds/stranger-things/street.jpg",
"mediaType": "image/jpeg",
"width": 960,
"height": 720,
"alt": "A small-town street from above"
},
"initials": "I",
"color": "#15803d",
"files": [],
"slots": []
},
"media_ref": "me16aecc4bcc99198",
"entity_ref": "e0ec130301b4376df",
"body": [
{
"$body": "Storyfeed/Body/Image",
"$v": 3,
"alt": "A small-town street from above",
"caption": "A small-town street from above",
"image": "preview"
}
],
"tombstone": null
}
],
"targets": [
{
"type": "venue",
"id": "103",
"label": "the Hawkins Post",
"link": {
"href": "/venues/post",
"modal": false,
"attributes": []
},
"data": [],
"media": {
"icon": null,
"image": null,
"preview": null,
"initials": "TP",
"color": "#15803d",
"files": [],
"slots": []
},
"media_ref": "m8d99a06bd4900dc8",
"entity_ref": "e70fb65f86688b833",
"body": null,
"tombstone": null
}
],
"contexts": [],
"origins": [],
"results": [],
"instruments": [],
"locations": [],
"generators": [],
"featured": [
{
"type": "photo",
"id": "3103",
"label": "IMG_3103.jpg",
"link": {
"href": "/photos/3103",
"modal": false,
"attributes": []
},
"data": [],
"media": {
"icon": null,
"image": null,
"preview": {
"src": "/media/worlds/stranger-things/darkroom.jpg",
"mediaType": "image/jpeg",
"width": 960,
"height": 720,
"alt": "A room lit red"
},
"initials": "I",
"color": "#4338ca",
"files": [],
"slots": []
},
"media_ref": "m927bf2541bf27668",
"entity_ref": "ec2557674a1d80c0c",
"body": [
{
"$body": "Storyfeed/Body/Image",
"$v": 3,
"alt": "A room lit red",
"caption": "A room lit red",
"image": "preview"
}
],
"tombstone": null
},
{
"type": "photo",
"id": "3102",
"label": "IMG_3102.jpg",
"link": {
"href": "/photos/3102",
"modal": false,
"attributes": []
},
"data": [],
"media": {
"icon": null,
"image": null,
"preview": {
"src": "/media/worlds/stranger-things/arcade.jpg",
"mediaType": "image/jpeg",
"width": 960,
"height": 720,
"alt": "Arcade machines in a dark room"
},
"initials": "I",
"color": "#b45309",
"files": [],
"slots": []
},
"media_ref": "m68b47766673ac40e",
"entity_ref": "ee5d966e85f54c9e6",
"body": [
{
"$body": "Storyfeed/Body/Image",
"$v": 3,
"alt": "Arcade machines in a dark room",
"caption": "Arcade machines in a dark room",
"image": "preview"
}
],
"tombstone": null
},
{
"type": "photo",
"id": "3101",
"label": "IMG_3101.jpg",
"link": {
"href": "/photos/3101",
"modal": false,
"attributes": []
},
"data": [],
"media": {
"icon": null,
"image": null,
"preview": {
"src": "/media/worlds/stranger-things/street.jpg",
"mediaType": "image/jpeg",
"width": 960,
"height": 720,
"alt": "A small-town street from above"
},
"initials": "I",
"color": "#15803d",
"files": [],
"slots": []
},
"media_ref": "me16aecc4bcc99198",
"entity_ref": "e0ec130301b4376df",
"body": [
{
"$body": "Storyfeed/Body/Image",
"$v": 3,
"alt": "A small-town street from above",
"caption": "A small-town street from above",
"image": "preview"
}
],
"tombstone": null
}
]
},
"distinct": {
"actors": 1,
"objects": 3,
"targets": 1,
"contexts": 0,
"origins": 0,
"results": 0,
"instruments": 0,
"locations": 0,
"generators": 0,
"featured": 3
},
"children": [
{
"kind": "activity",
"id": "j56",
"verb": "upload",
"published_at": "1985-06-30T11:05:00.000000Z",
"starts_at": null,
"ends_at": null,
"headline_template": ":actor uploaded :object to :target",
"headline": null,
"bindings": null,
"glyph": "image",
"glyph_intent": null,
"actor": {
"type": "user",
"id": "105",
"label": "Jonathan Byers",
"link": {
"href": "/users/105",
"modal": false,
"attributes": []
},
"data": [],
"media": {
"icon": null,
"image": null,
"preview": null,
"initials": "JB",
"color": "#be123c",
"files": [],
"slots": []
},
"media_ref": "m9f6d41167f25287a",
"entity_ref": "e02444442f97e8ea2",
"body": null,
"tombstone": null
},
"object": {
"type": "photo",
"id": "3103",
"label": "IMG_3103.jpg",
"link": {
"href": "/photos/3103",
"modal": false,
"attributes": []
},
"data": [],
"media": {
"icon": null,
"image": null,
"preview": {
"src": "/media/worlds/stranger-things/darkroom.jpg",
"mediaType": "image/jpeg",
"width": 960,
"height": 720,
"alt": "A room lit red"
},
"initials": "I",
"color": "#4338ca",
"files": [],
"slots": []
},
"media_ref": "m927bf2541bf27668",
"entity_ref": "ec2557674a1d80c0c",
"body": [
{
"$body": "Storyfeed/Body/Image",
"$v": 3,
"alt": "A room lit red",
"caption": "A room lit red",
"image": "preview"
}
],
"tombstone": null
},
"target": {
"type": "venue",
"id": "103",
"label": "the Hawkins Post",
"link": {
"href": "/venues/post",
"modal": false,
"attributes": []
},
"data": [],
"media": {
"icon": null,
"image": null,
"preview": null,
"initials": "TP",
"color": "#15803d",
"files": [],
"slots": []
},
"media_ref": "m8d99a06bd4900dc8",
"entity_ref": "e70fb65f86688b833",
"body": null,
"tombstone": null
},
"context": null,
"origin": null,
"result": null,
"instrument": null,
"location": null,
"generator": null,
"featured": "object",
"data": null,
"tombstoned": [],
"redundant": false,
"missing_headline_template": null,
"missing_headline": null
},
{
"kind": "activity",
"id": "j55",
"verb": "upload",
"published_at": "1985-06-30T11:02:00.000000Z",
"starts_at": null,
"ends_at": null,
"headline_template": ":actor uploaded :object to :target",
"headline": null,
"bindings": null,
"glyph": "image",
"glyph_intent": null,
"actor": {
"type": "user",
"id": "105",
"label": "Jonathan Byers",
"link": {
"href": "/users/105",
"modal": false,
"attributes": []
},
"data": [],
"media": {
"icon": null,
"image": null,
"preview": null,
"initials": "JB",
"color": "#be123c",
"files": [],
"slots": []
},
"media_ref": "m9f6d41167f25287a",
"entity_ref": "e02444442f97e8ea2",
"body": null,
"tombstone": null
},
"object": {
"type": "photo",
"id": "3102",
"label": "IMG_3102.jpg",
"link": {
"href": "/photos/3102",
"modal": false,
"attributes": []
},
"data": [],
"media": {
"icon": null,
"image": null,
"preview": {
"src": "/media/worlds/stranger-things/arcade.jpg",
"mediaType": "image/jpeg",
"width": 960,
"height": 720,
"alt": "Arcade machines in a dark room"
},
"initials": "I",
"color": "#b45309",
"files": [],
"slots": []
},
"media_ref": "m68b47766673ac40e",
"entity_ref": "ee5d966e85f54c9e6",
"body": [
{
"$body": "Storyfeed/Body/Image",
"$v": 3,
"alt": "Arcade machines in a dark room",
"caption": "Arcade machines in a dark room",
"image": "preview"
}
],
"tombstone": null
},
"target": {
"type": "venue",
"id": "103",
"label": "the Hawkins Post",
"link": {
"href": "/venues/post",
"modal": false,
"attributes": []
},
"data": [],
"media": {
"icon": null,
"image": null,
"preview": null,
"initials": "TP",
"color": "#15803d",
"files": [],
"slots": []
},
"media_ref": "m8d99a06bd4900dc8",
"entity_ref": "e70fb65f86688b833",
"body": null,
"tombstone": null
},
"context": null,
"origin": null,
"result": null,
"instrument": null,
"location": null,
"generator": null,
"featured": "object",
"data": null,
"tombstoned": [],
"redundant": false,
"missing_headline_template": null,
"missing_headline": null
},
{
"kind": "activity",
"id": "j54",
"verb": "upload",
"published_at": "1985-06-30T11:00:00.000000Z",
"starts_at": null,
"ends_at": null,
"headline_template": ":actor uploaded :object to :target",
"headline": null,
"bindings": null,
"glyph": "image",
"glyph_intent": null,
"actor": {
"type": "user",
"id": "105",
"label": "Jonathan Byers",
"link": {
"href": "/users/105",
"modal": false,
"attributes": []
},
"data": [],
"media": {
"icon": null,
"image": null,
"preview": null,
"initials": "JB",
"color": "#be123c",
"files": [],
"slots": []
},
"media_ref": "m9f6d41167f25287a",
"entity_ref": "e02444442f97e8ea2",
"body": null,
"tombstone": null
},
"object": {
"type": "photo",
"id": "3101",
"label": "IMG_3101.jpg",
"link": {
"href": "/photos/3101",
"modal": false,
"attributes": []
},
"data": [],
"media": {
"icon": null,
"image": null,
"preview": {
"src": "/media/worlds/stranger-things/street.jpg",
"mediaType": "image/jpeg",
"width": 960,
"height": 720,
"alt": "A small-town street from above"
},
"initials": "I",
"color": "#15803d",
"files": [],
"slots": []
},
"media_ref": "me16aecc4bcc99198",
"entity_ref": "e0ec130301b4376df",
"body": [
{
"$body": "Storyfeed/Body/Image",
"$v": 3,
"alt": "A small-town street from above",
"caption": "A small-town street from above",
"image": "preview"
}
],
"tombstone": null
},
"target": {
"type": "venue",
"id": "103",
"label": "the Hawkins Post",
"link": {
"href": "/venues/post",
"modal": false,
"attributes": []
},
"data": [],
"media": {
"icon": null,
"image": null,
"preview": null,
"initials": "TP",
"color": "#15803d",
"files": [],
"slots": []
},
"media_ref": "m8d99a06bd4900dc8",
"entity_ref": "e70fb65f86688b833",
"body": null,
"tombstone": null
},
"context": null,
"origin": null,
"result": null,
"instrument": null,
"location": null,
"generator": null,
"featured": "object",
"data": null,
"tombstoned": [],
"redundant": false,
"missing_headline_template": null,
"missing_headline": null
}
],
"children_truncated": false,
"tombstoned": [],
"redundant": false,
"distinct_tombstoned": {
"actors": 0,
"objects": 0,
"targets": 0,
"contexts": 0,
"origins": 0,
"results": 0,
"instruments": 0,
"locations": 0,
"generators": 0,
"featured": 0
}
}
]| Key | Holds |
|---|---|
featured | the role every member features, when the axis pins that role to one entity, which is then in the role's key; otherwise null |
sample.featured | each sampled member's featured entity, newest first; a member that features nothing adds no entry |
distinct.featured | how many members across the whole group feature an entity |
distinct_tombstoned.featured | how many of those entities are tombstones |
grouping.sample_limits.featured caps sample.featured, three by default.
Configuring Curation
See Choosing a Read Mode for Live and Log. Curation controls which groups Live reads:
| Mode | Returns |
|---|---|
live(), grouping.curate = true (default) | groups selected across the available axes, with a repeat group when no other group is selected |
live(), grouping.curate = false | repeat groups and composites, regardless of inferred groups selected earlier |
Set grouping.curate to false for repeat-only live() reads. storyfeed:curate chooses groups for recent activities and runs hourly through Laravel's scheduler.
Grouping Axes
Built-In Axes
Live selects people acting on one thing first: actors for the same object, then actors_target for the same target. It next selects one person acting across things in the same context, then actions on one object, then repeats. Two entities match when their type and ID match. Every built-in group contains one verb and one context, within a burst window.
| Axis | Shared Values | What May Differ | Singular Tokens Allowed |
|---|---|---|---|
actors | verb, object, target, context | actor | :object, :target, :context |
actors_target | verb, target, context | actor, object | :target, :context |
targets | actor, verb, context | target, object | :actor, :context |
object | actor, verb, object, target, context | activity data | :actor, :object, :target, :context |
repeat | actor, verb, object type, target, context | object identity | :actor, :target, :context |
composite | actor, target and context of one published activity | members of its object collection | :actor, :target, :context |
Origin, result, instrument, location, generator and activity data may differ. A composite is one published activity with a collection of objects; see Composites.
Shared values alone do not select a group: activities must also meet the thresholds, and Storyfeed must select the group. Default Grouping Keys lists their keys.
Headlines for actors, repeat and object groups may go in a Story class or inside Story::for() because each group contains one object type. Define headlines for actors_target and targets on the verb alone.
Configuring Grouping Thresholds
'grouping' => [
'policy' => [
'min_actors' => 3,
'min_targets' => 2,
'min_target_members' => 3,
'min_object_members' => 2,
],
],| Key | What the Axis Needs | Default |
|---|---|---|
min_actors | actors or actors_target: this many different actors | 3 |
min_targets | targets: this many different targets | 2 |
min_target_members | targets: this many activities | 3 |
min_object_members | object: this many activities on the one object | 2 |
Two customers at the same shop do not meet min_actors: 3. With no other qualifying group, each remains an individual item:
Three customers meet the threshold and form an actors group:
Activities below a threshold cannot form that group. They fall back to repeat when no other group qualifies. After changing thresholds, run php artisan storyfeed:curate to re-evaluate existing groups. Changes to an axis's grouping key or newly registered axes require rehashing.
See Live Burst Windows to choose the quiet gap and maximum duration shared by grouped activities.
Defining Group Headlines
Pass one headline per axis to grouped(), as in the repeat and actors examples. Where you declare it determines which groups use it.
Definition Scope
| Written In | Key | Used For |
|---|---|---|
Story::for(Order::class)->verb('place'), or a Story class's place() | repeat.order.place | groups of orders |
Story::verb('place') | repeat.place | groups of any type |
Storyfeed tries the key with the group's type first, then the key without it.
Choose the declaration location from the built-in axis table: actors, repeat and object share an object type; actors_target and targets may span types.
A type-level headline may name that type because every member shares it. A verb-level headline may describe several object types, so avoid naming a particular type.
Singular and Plural Tokens
| Singular Token | Plural Token | Entity Role |
|---|---|---|
:actor | :actors | who acted |
:object | :objects | what the activity acted on |
:target | :targets | what the activity was directed at |
:context | :contexts | the surrounding container |
:origin | :origins | the source |
:result | :results | the produced entity |
:instrument | :instruments | the tool or service used |
:location | :locations | where the action happened |
:generator | :generators | the app or agent that produced the activity |
A plural token displays a few names and a count of the rest. See Building Your Own Components for details. :count is the number of activities in the group, not of distinct objects; see the repeated-order example for wording that keeps this visible.
A singular token is allowed only when every activity shares that role, as shown in Singular Tokens Allowed. Plural tokens are allowed in any group headline.
// a repeat group: one customer, many dishes
':actor changed the price of :object :count times' // Invalid: objects differ within this repeat group.
':actor changed :count prices' // Counts activities.
':actor changed :count prices on :targets' // Lists the targets.Both headlines use allowed tokens, but three lists make the first hard to read:
// an actors group: every member shares :target
':actors placed :objects with :targets' // Three lists of names.
':actors ordered from :target' // One list and the shared target.Use one list per headline and replace the others with :count.
Missing Roles
A plural token lists only filled roles. The targets axis groups by actor, verb, context and burst window. An activity with an empty target can therefore join the group: it contributes to :count but adds no name.
// a targets group of 5 members, 2 of them carrying a target
':actor asked about :count dishes' // Counts five activities as five dishes.
':actor asked about :targets' // Lists the two recorded targets.The first headline says there are five dishes when only two are recorded. Storyfeed does not check nouns beside :count.
Fallback Nouns
When no group headline is defined, Storyfeed uses the single-activity headline if its roles can be represented for the group. A role that differs across the group becomes a plain noun, such as "dishes", when the axis pins its type, as repeat pins the object type. Otherwise both headline_template and headline are null. See Groups Without Headlines for rendering the count. Single-activity headline closures cannot supply this fallback because they access one member's data rather than the whole group.
Give a type its noun:
use App\Models\MenuItem;
use Storyfeed\Facades\Story;
Story::for(MenuItem::class)->fallback()->noun('dish|dishes');
Story::for(MenuItem::class)->verb('add')->headline(':actor put :object on the menu');- Price
- $2.95
- Section
- Sundaes
- Available
- At the counter
- Orders
- 12
Supply both forms; Storyfeed does not derive plurals. For more plural forms, add pipe segments. See Localization for translated nouns. The default is item|items.
The entity count selects the form: FeedNoun::form('dish|dishes', 7) returns dishes. The headline :actor put :object on the menu becomes :actor put dishes on the menu. The noun is plain text; :actor remains a link.
Fallback Headlines
| Available Headline | Payload |
|---|---|
| An authored group headline | The authored template or finished text. |
| A safe single-activity template | The single-activity template with unshared roles replaced by nouns where possible; no count is added automatically. |
| Neither a group headline nor a safe single-activity template | Both headline_template and headline are null; member counts and children remain available. |
The authored headline counts the placements:
A noun fallback can say “placed orders” without saying how many:
A template whose tokens all refer to shared roles is safe to reuse, but its prose can still undercount. “Placed an order” below describes three activities as one:
Token validation checks that roles are shared; it does not check the words “an order”. Write an explicit group headline, such as the repeat headline above. If individual details matter, use log() instead.
With both headline fields absent, the count and member rows remain visible:
See Groups Without Headlines to render this payload.
See Custom Axes to define grouping keys, eligibility, and priority.