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

The Feed File ​

Define activity headlines, icons, and group headlines in routes/feed.php. The installer creates this file.

Basic Definitions ​

Defining a Headline ​

A headline describes an activity using a template:

routes/feed.php
php
use App\Models\Order;
use Storyfeed\Facades\Story;

Story::for(Order::class)
    ->verb('place')
    ->headline(':actor placed :object at :target');
Erica Sinclair

The for method specifies the object type, and the verb method specifies the recorded verb. This headline applies to place activities involving an order.

Headline Templates ​

Role Tokens ​

TokenEntity
:actorwho performed the action
:objectthe entity acted on
:targetthe entity the action was directed at
:contextthe containing entity
:originthe source
:resultthe entity produced
:instrumentthe tool or service used
:locationwhere the action happened
:generatorthe app or agent that produced the activity

Each token is replaced with the entity's label and linked when it has a URL.

Optional Segments ​

Enclose an optional phrase in square brackets to include it only when its referenced roles are filled:

routes/feed.php
php
use App\Models\Order;
use Storyfeed\Facades\Story;

Story::for(Order::class)
    ->verb('place')
    ->headline(':actor placed :object[ at :target]');
Erica Sinclair
Erica Sinclair

Storyfeed resolves optional segments before returning the payload. In this example, it includes at :target only when the activity has a target. Without brackets, an empty role stays in the template. The headline reader renders it as “Someone” for :actor or “Something” for another role. Use optional segments to omit the connecting words along with an empty role.

Dynamic Headlines ​

To choose a headline for each activity, pass a closure that returns a template:

routes/feed.php
php
use App\Models\Order;
use Storyfeed\Facades\Story;
use Storyfeed\ActivityContext;

Story::for(Order::class)
    ->verb('place')
    ->headline(
        fn (ActivityContext $activity) => $activity->boolean('rush')
            ? ':actor rushed :object to :target'
            : ':actor placed :object at :target',
    );
Erica Sinclair
Erica Sinclair

The closure receives an ActivityContext, which provides typed helpers for the activity’s data and accessors for its roles. It runs when Storyfeed retrieves the feed. Returned role tokens are rendered as entity labels and links.

Icons and Intents ​

routes/feed.php
php
use App\Models\Order;
use Storyfeed\Facades\Story;

Story::for(Order::class)
    ->verb('place')
    ->headline(':actor placed :object at :target')
    ->icon('shopping-bag');

Story::for(Order::class)
    ->verb('complete')
    ->headline(':actor completed :object')
    ->icon('receipt');
Steve Harrington
Erica Sinclair

Use the intent method to assign an application-defined value, such as success or danger. Add it to the verb's definition, and Storyfeed returns it in the glyph_intent field:

routes/feed.php
php
use App\Models\Order;
use Storyfeed\Facades\Story;

Story::for(Order::class)
    ->verb('complete')
    ->headline(':actor completed :object')
    ->icon('receipt')
    ->intent('success'); 
Steve Harrington
[
  {
    "kind": "activity",
    "id": "a-complete",
    "verb": "complete",
    "published_at": "1985-07-02T12:08:00.000000Z",
    "starts_at": null,
    "ends_at": null,
    "headline_template": ":actor completed :object",
    "headline": null,
    "bindings": null,
    "glyph": "receipt",
    "glyph_intent": "success",
    "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": []
      },
      "media_ref": "md08aeb0f13f95241",
      "entity_ref": "e6b153676d8dbc853",
      "body": null,
      "tombstone": null
    },
    "object": {
      "type": "order",
      "id": "1035",
      "label": "Order #1035",
      "link": {
        "href": "/orders/1035",
        "modal": false,
        "attributes": []
      },
      "data": [],
      "media": {
        "icon": null,
        "image": null,
        "preview": null,
        "initials": "O1",
        "color": "#4d7c0f",
        "files": [],
        "slots": []
      },
      "media_ref": "ma9527581042280f7",
      "entity_ref": "e722f0b114fd1ec13",
      "body": null,
      "tombstone": null
    },
    "target": {
      "type": "venue",
      "id": "101",
      "label": "Scoops Ahoy",
      "link": {
        "href": "/venues/scoops",
        "modal": false,
        "attributes": []
      },
      "data": [],
      "media": {
        "icon": null,
        "image": null,
        "preview": {
          "src": "/media/worlds/stranger-things/parlour.jpg",
          "mediaType": "image/jpeg",
          "width": 960,
          "height": 720,
          "alt": "An ice cream counter"
        },
        "initials": "SA",
        "color": "#9f1239",
        "files": [],
        "slots": []
      },
      "media_ref": "m1bcad7c79ddfc05d",
      "entity_ref": "e352bb6f37b7d8bfe",
      "body": [
        {
          "$body": "Storyfeed/Body/Image",
          "$v": 3,
          "alt": "Scoops Ahoy",
          "caption": "Scoops Ahoy",
          "image": "preview"
        }
      ],
      "tombstone": 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
  }
]

See Building Your Own Components to display the icon and apply its intent.

Definition Groups ​

routes/feed.php
php
use App\Models\Order;
use Storyfeed\Facades\Story;

Story::for(Order::class)->group(function () {
    Story::verb('place')->headline(':actor placed :object at :target');
    Story::verb('complete')->headline(':actor completed :object');
});
Steve Harrington
Erica Sinclair

All verb definitions inside the closure apply to orders.

Resource Definitions ​

The resource method on the Story facade defines create, update, delete, and restore for a model:

routes/feed.php
php
use App\Models\Order;
use Storyfeed\Facades\Story;

Story::resource(Order::class);
Steve Harrington
VerbHeadlineIcon
create:actor created :objectplus
update:actor updated :objectpencil
delete:actor deleted :objecttrash
restore:actor restored :objectrotate-ccw

Use the only or except methods to select resource verbs. Exclude a verb before defining it separately:

routes/feed.php
php
use App\Models\Order;
use Storyfeed\Facades\Story;

Story::resource(Order::class)->except('update');

Story::for(Order::class)->verb('update')->headline(':actor changed :object');

Two inline definitions of the same verb that set the same field, such as two headlines or two icons, throw, naming both locations. To replace one resource verb with its own class, see Supplementing Resource Stories.

Definition Precedence ​

Storyfeed applies definitions in this order, from most to least specific:

DeclarationMatches
Story::for(Order::class)->verb('place')that verb on that object type
Story::for(Order::class)->fallback()every verb on that object type
Story::verb('place')that verb on any object type
Story::fallback()everything with no more specific entry

This precedence applies to headlines, icons and intents. Use a fallback to define a headline for order verbs without their own definition:

routes/feed.php
php
use App\Models\Order;
use Storyfeed\Facades\Story;

Story::for(Order::class)->fallback()->headline(':actor updated :object');
Steve Harrington

You may also define group headlines and headlines for deleted models.

See Overriding a Package's Stories to change supplied definitions in your feed file.

Listing Definitions ​

List the definitions loaded by your application:

bash
php artisan storyfeed:list

Use --type=order or --verb=place to filter definitions, and --json for JSON output. Entries include declarations from service providers and the feed file, with their headline, icon, and source location. Explicit overrides are marked in the listing. See Commands for all options.

Caching Definitions ​

Cache definitions during deployment:

bash
php artisan storyfeed:cache

The cache includes stories registered by service providers and the feed file. See Caching Definitions for how cached feeds and authored listings differ. The optimize Artisan command also caches these definitions. Rebuild the cache after changing them. To clear it:

bash
php artisan storyfeed:clear

Storyfeed serializes closure headlines into the cache. If a closure cannot be serialized, the command fails and reports its source location. See Commands.

As definitions grow, move a model's verbs into a Story class.

Released under the MIT License.