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

Containers & Context ​

Introduction ​

The context role records where an activity happened, such as the shop a dish belongs to. Use it to retrieve activities within that shop.

Recording Context ​

Record the context when publishing. Storyfeed does not fill roles later, so a context filter can only find activities recorded with that context.

php
Storyfeed::activity()
    ->by($request->user())
    ->action('ask', $note)
    ->on($dish)           // target: what the question is about
    ->context($shop)      // context: the shop the dish belongs to
    ->publish();
php
Storyfeed::record(
    verb: 'ask',
    object: $note,
    actor: $request->user(),
    target: $dish,        // what the question is about
    context: $shop,       // the shop the dish belongs to
);

Choosing Between Target and Context ​

RoleHoldsIn the Sentence
targetwhat the action was directed atasked about the dish
contextwhere it happenedin the shop

Use context when the target belongs to a container, such as a dish in a shop. If the target is the container itself, the target role is enough:

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

Record every role that describes what happened, even if the headline omits it. Storyfeed also uses roles for filtering and grouping.

Set the context when you need to filter by it or include it in a headline:

UsageWhy It Needs context
Storyfeed::feed()->context($shop)finds only activities recorded with that context
:context in a headlinedisplays the entity recorded in the context role

Reading Activities in a Container ​

The context method filters activities recorded within the shop. The involving method also includes activities about the shop itself, such as its creation.

Using Non-Model Containers ​

To use a name as the context, pass a string such as ->context('Saturday service'). Storyfeed creates a party for the name. The :context token displays it, and Storyfeed::feed()->context('Saturday service') retrieves its activities.

Each distinct name creates a separate party. To store a value without assigning a role, use ->data(['service' => $name]). It is returned in the activity's data and cannot be used as a headline role token.

Use Activity Scopes to supply context across a callback or HTTP request.

Released under the MIT License.