Recording Value Changes
Introduction
A manager renames the "Summer" menu to "Late Summer". The feed should say "renamed Summer to Late Summer". Passing the two names as roles makes each name a participant, so a search for a party named "Summer" finds a menu name. The names are values, and the recipe records them that way.
Record the entity being renamed as the object. Bind its old and new names to headline tokens so the names remain values throughout filtering and serialization, and print exactly as the manager typed them.
Comparing String Roles
A string passed to to or context creates or reuses a named party. This composition gives both names participant identities:
use App\Models\Menu;
use Storyfeed\Facades\Story;
// Before: the headline displays values stored as parties.
Story::for(Menu::class)->verb('rename')
->headline(':actor renamed :context to :target');use App\Models\Menu;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use Storyfeed\Facades\Storyfeed;
Route::patch('/menus/{menu}/name', function (Request $request, Menu $menu) {
$input = $request->validate(['name' => ['required', 'string', 'max:100']]);
$from = $menu->name;
$menu->update(['name' => $input['name']]);
Storyfeed::activity()
->by($request->user())
->action('rename', $menu)
->context($from) // Before: creates a party for the old name.
->to($menu->name) // Before: creates a party for the new name.
->publish();
return back();
})->middleware('auth');use App\Models\Menu;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use Storyfeed\Facades\Storyfeed;
Route::patch('/menus/{menu}/name', function (Request $request, Menu $menu) {
$input = $request->validate(['name' => ['required', 'string', 'max:100']]);
$from = $menu->name;
$menu->update(['name' => $input['name']]);
Storyfeed::record(
verb: 'rename',
object: $menu,
actor: $request->user(),
target: $menu->name, // Before: creates a party for the new name.
context: $from, // Before: creates a party for the old name.
);
return back();
})->middleware('auth');[
{
"kind": "activity",
"id": "rename-before",
"verb": "rename",
"published_at": "1985-07-02T12:00:00.000000Z",
"starts_at": null,
"ends_at": null,
"headline_template": ":actor renamed :context to :target",
"headline": null,
"bindings": null,
"glyph": "pencil",
"glyph_intent": null,
"actor": {
"type": "user",
"id": "101",
"label": "Steve Harrington",
"link": {
"href": "/users/101",
"modal": false,
"attributes": []
},
"data": [],
"media": {
"icon": {
"src": "/media/worlds/stranger-things/avatars/scooper.jpg",
"mediaType": "image/jpeg",
"width": 256,
"height": 256,
"alt": null
},
"image": null,
"preview": null,
"initials": null,
"color": null,
"files": [],
"slots": []
},
"body": null,
"tombstone": null
},
"object": {
"type": "menu",
"id": "menu-rename",
"label": "Seasonal menu",
"link": {
"href": "/menus/menu-rename",
"modal": false,
"attributes": []
},
"data": [],
"media": {
"icon": null,
"image": null,
"preview": null,
"initials": "SM",
"color": "#a21caf",
"files": [],
"slots": []
},
"body": null,
"tombstone": null
},
"target": {
"type": "storyfeed.entity",
"id": "name-after",
"label": "Seasonal menu",
"link": null,
"data": [],
"media": {
"icon": null,
"image": null,
"preview": null,
"initials": "SM",
"color": "#b45309",
"files": [],
"slots": []
},
"body": null,
"tombstone": null
},
"context": {
"type": "storyfeed.entity",
"id": "name-before",
"label": "Counter menu",
"link": null,
"data": [],
"media": {
"icon": null,
"image": null,
"preview": null,
"initials": "CM",
"color": "#1d4ed8",
"files": [],
"slots": []
},
"body": null,
"tombstone": 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
}
]Binding the Names
Replace the definition with a headline that names a token for each value:
use App\Models\Menu;
use Storyfeed\Facades\Story;
Story::for(Menu::class)->verb('rename')
->headline(':actor renamed :old to :new');Replace the route with this recording. The menu is still the object, and bind() supplies each name:
use App\Models\Menu;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use Storyfeed\Facades\Storyfeed;
Route::patch('/menus/{menu}/name', function (Request $request, Menu $menu) {
$input = $request->validate(['name' => ['required', 'string', 'max:100']]);
$from = $menu->name;
$menu->update(['name' => $input['name']]);
Storyfeed::activity()
->by($request->user())
->action('rename', $menu)
->bind('old', $from)
->bind('new', $menu->name)
->publish();
return back();
})->middleware('auth');use App\Models\Menu;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use Storyfeed\Facades\Storyfeed;
Route::patch('/menus/{menu}/name', function (Request $request, Menu $menu) {
$input = $request->validate(['name' => ['required', 'string', 'max:100']]);
$from = $menu->name;
$menu->update(['name' => $input['name']]);
Storyfeed::record(
verb: 'rename',
object: $menu,
actor: $request->user(),
bind: ['old' => $from, 'new' => $menu->name],
);
return back();
})->middleware('auth');[
{
"kind": "activity",
"id": "rename-after",
"verb": "rename",
"published_at": "1985-07-02T12:00:00.000000Z",
"starts_at": null,
"ends_at": null,
"headline_template": ":actor renamed :old to :new",
"headline": null,
"bindings": {
"old": "Counter menu",
"new": "Seasonal menu"
},
"glyph": "pencil",
"glyph_intent": null,
"actor": {
"type": "user",
"id": "101",
"label": "Steve Harrington",
"link": {
"href": "/users/101",
"modal": false,
"attributes": []
},
"data": [],
"media": {
"icon": {
"src": "/media/worlds/stranger-things/avatars/scooper.jpg",
"mediaType": "image/jpeg",
"width": 256,
"height": 256,
"alt": null
},
"image": null,
"preview": null,
"initials": null,
"color": null,
"files": [],
"slots": []
},
"body": null,
"tombstone": null
},
"object": {
"type": "menu",
"id": "menu-rename",
"label": "Seasonal menu",
"link": {
"href": "/menus/menu-rename",
"modal": false,
"attributes": []
},
"data": [],
"media": {
"icon": null,
"image": null,
"preview": null,
"initials": "SM",
"color": "#a21caf",
"files": [],
"slots": []
},
"body": null,
"tombstone": null
},
"target": 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
}
]| Field | String Roles | Bindings |
|---|---|---|
actor | the staff member | the staff member |
object | the menu | the menu |
target | a party named after the new name | empty |
context | a party named after the old name | empty |
bindings | empty | old and new names |
The headline has the same words in both examples. The second composition keeps the menu's identity separate from its names.
Don't build the headline by concatenating the names into it, as in ':actor renamed '.$from.' to '.$to. A name is user-entered text: a menu called Brunch [weekends] or Specials :object would be read as an optional segment or a token. A bound value never enters the template, so it prints exactly as entered, and the payload carries it in bindings beside the template's :old and :new.
Inspecting Parties
For a fresh database, run each composition separately with the same rename. Retrieve parties without creating any:
use Illuminate\Support\Str;
use Storyfeed\Models\Party;
$keys = array_map(Str::slug(...), ['Counter menu', 'Seasonal menu']);
Party::query()->whereIn('key', $keys)->orderBy('name')->pluck('name')->all();| Composition | Party Query Result |
|---|---|
| String roles | ['Counter menu', 'Seasonal menu'] |
| Bindings | [] |
The bound composition creates no parties for the names. It does not remove parties or change activities already recorded with the first composition. Storyfeed::feed()->involving($menu) finds either activity by the menu model. A party filter such as involving('Counter menu') finds the first composition. It does not search the second activity's bound values.
Doctor Findings
storyfeed:doctor lists the parties your activities use; see its parties.* findings. They do not decide whether a name belongs in a binding.
Choosing Participants and Values
Ask whether the thing has an identity you want to retrieve activities for or list as a participant. A shop, document, or payment service does. A changed name, destination email address, amount, date, or setting describes an event; bind it to a headline token with bind(), and store it in data as well when your own code needs to read it.
| Change or Detail | Participant | Bound Value |
|---|---|---|
| Rename or legal-name change | the entity being renamed | old and new names |
| Email delivery | the document or message | destination address |
| Payment | the payment or order | amount and payment method |
| Presentation change | the page or document | font and spacing settings |
Assigning Roles defines the participants. Use Containers & Context when the activity also needs a containing entity.
For a link's intended recipient, see A Link Sent to Someone, which records the fetch without assigning the recipient as actor.