Pre-1.0. Not intended for public use yet. The API is subject to undocumented change, and these pages may already be wrong about it.

Skip to content

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:

routes/feed.php
php
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');
routes/web.php
php
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');
php
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');
Steve Harrington
Steve Harrington renamed Counter menu to Seasonal menu
[
  {
    "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:

routes/feed.php
php
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:

routes/web.php
php
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');
php
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');
Steve Harrington
Steve Harrington renamed Counter menu to Seasonal menu
[
  {
    "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
  }
]
FieldString RolesBindings
actorthe staff memberthe staff member
objectthe menuthe menu
targeta party named after the new nameempty
contexta party named after the old nameempty
bindingsemptyold 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:

An Artisan Tinker session
php
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();
CompositionParty 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 DetailParticipantBound Value
Rename or legal-name changethe entity being renamedold and new names
Email deliverythe document or messagedestination address
Paymentthe payment or orderamount and payment method
Presentation changethe page or documentfont 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.

Released under the MIT License.