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

Choosing to Record or Compose ​

Introduction ​

A menu item's page should show its price history, and the shop's feed should show what staff did today. The app already keeps a price_changes table. Recording every price change as an activity would store the same history twice, but composing the shop feed at read time would miss events the app never stored. Each need has a better fit.

Record an activity when it happens, or compose a feed from what your app already stores when the page is read.

Choosing ​

NeedUse
the event appears in other feeds, such as the shop'srecord
involving() finds it from any entity it namesrecord
the value it describes is overwritten later, such as a status or a pricerecord: its data keeps the value at the time
busy activity groups across records in Liverecord
the app already stores each step, in a table or in timestampscompose
it belongs on one record's pagecompose

Composing From a History Table ​

A menu item's page shows its price changes from the app's own price_changes table. Nothing is recorded:

app/Http/Controllers/MenuItemController.phpshow()
php
use App\Models\PriceChange;
use Illuminate\Support\Number;
use Storyfeed\Facades\Storyfeed;

return view('menu-items.show', [
    'item' => $item,
    'prices' => Storyfeed::compose()
        ->addMany($item->priceChanges, fn (PriceChange $change, $entry) => $entry
            ->headline(':actor changed the price of :object to :price', [
                'actor' => $change->user,
                'object' => $item,
                'price' => Number::currency($change->price),
            ])
            ->publishedAt($change->created_at))
        ->get(),
]);
Steve Harrington
Steve Harrington changed the price of USS Butterscotch to $4.50
Steve Harrington
Steve Harrington changed the price of USS Butterscotch to $4.25
Steve Harrington
Steve Harrington changed the price of USS Butterscotch to $3.95

The entries read newest first. Each headline is its own, so the entries need no verb and no feed file definition.

Knowing the Limits ​

  • A composed feed reads only the entries you add: it can't include recorded activities.
  • It reads as Log unless you call live().
  • involving(), query() and members() throw. See Source Limitations.

To show both on one page, record the events and compose the rest into a separate feed.

Released under the MIT License.