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 a Verb ​

Choose a verb that describes the event, then use roles to identify what was involved.

Naming Verbs ​

The verb describes what happened; the object identifies what it happened to:

php
Storyfeed::activity()
    ->by($request->user())
    ->action('place', $order)   // not 'order.place'
    ->to($shop)
    ->publish();
php
Storyfeed::record(
    verb: 'place',   // not 'order.place'
    object: $order,
    actor: $request->user(),
    target: $shop,
);

Headlines are defined by object type and verb, so including the type in the verb repeats information. A verb such as place also works for other types.

Use roles for details that would otherwise become part of the verb:

Instead ofRecord
doctrine.clause_addadd, with the clause as object and the doctrine as target
menu.item_publishpublish, with the menu item as object and the menu as target

Use present-tense verbs such as place. Use past tense in headlines: :actor placed :object.

Choose the word that describes the event in your application. Verb Vocabulary lists every built-in verb.

PairUse the first whenUse the second when
create / addthe object did not exist before the activityan existing object joins a collection, identified by the target
delete / removethe object no longer existsthe object still exists but has left a collection, such as through archiving
remove / undothe object leaves a collectionan earlier action is reversed; use restore for restoring a model
offer / invitesomething is sent for a response, such as a documentsomeone is asked to participate, such as signing the document
accept / likethe action responds to an offer or invite, including approvalthe action is an unprompted reaction
view / reada page opens or a preview loads; use view when unsurethe object is deliberately obtained, such as by downloading a file

Choosing Create or Add ​

Use create for a new menu item:

php
$product = MenuItem::create($request->validated());   // a new menu item

Act::Create->by($request->user())->object($product)->publish(); 
php
$product = MenuItem::create($request->validated());   // a new menu item

Storyfeed::record(
    verb: Act::Create, 
    object: $product,
    actor: $request->user(),
);

Use add when putting an existing menu item on a menu:

php
$menu->menuItems()->attach($product);   // the menu item already existed

Act::Add->by($request->user())->object($product)->to($menu)->publish(); 
php
$menu->menuItems()->attach($product);   // the menu item already existed

Storyfeed::record(
    verb: Act::Add, 
    object: $product,
    actor: $request->user(),
    target: $menu,
);

add uses a target to identify the collection. Without a target, create may better describe the event.

See Recording Activities for roles and publishedAt(), which distinguish events that share a verb.

Released under the MIT License.