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

Quickstart ​

Introduction ​

Record an activity and display it with the Blade kit. Prepare the models, define a headline, and publish the activity from your application. This example records a customer placing an order with a shop.

Preparing the Models ​

Install Storyfeed before defining your models and headline.

To include the Order model in an activity, implement the Feedable interface and use the InteractsWithFeed trait. Define its label in the toFeed method:

app/Models/Order.php
php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Storyfeed\Concerns\InteractsWithFeed;
use Storyfeed\Contracts\Feedable;
use Storyfeed\FeedEntity;

class Order extends Model implements Feedable
{
    use InteractsWithFeed;

    public function toFeed(): FeedEntity
    {
        return FeedEntity::make()->label("Order #{$this->reference}");
    }
}
php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Storyfeed\Concerns\InteractsWithFeed;
use Storyfeed\Contracts\Feedable;
use Storyfeed\FeedEntity;

class Order extends Model implements Feedable
{
    use InteractsWithFeed;

    public function toFeed(): FeedEntity
    {
        return FeedEntity::make(
            label: "Order #{$this->reference}",
        );
    }
}

Do the same for Shop and User. If you omit the toFeed method, Storyfeed generates a default label from the model's attributes, such as name.

Defining a Headline ​

Define a headline for the place verb in routes/feed.php:

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

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

Publishing an Activity ​

Publish the activity where your application places the order:

Where the order is placed: a controller, an action, a listener
php
use Storyfeed\Facades\Storyfeed;

Storyfeed::activity()
    ->by($customer)
    ->action('place', $order)
    ->to($shop)
    ->publish();
php
use Storyfeed\Facades\Storyfeed;

Storyfeed::record(
    verb: 'place',
    object: $order,
    actor: $customer,
    target: $shop,
);
ES
Erica Sinclair placed Order #1035 with Scoops Ahoy

Retrieving the Feed ​

To retrieve a page of activities, call the feed method on the Storyfeed facade, followed by the get method. You may return the result from a route:

routes/web.php
php
use Illuminate\Support\Facades\Route;
use Storyfeed\Facades\Storyfeed;

Route::get('/', function () {
    return Storyfeed::feed()->get();
});

The route returns a JSON payload:

[
  {
    "kind": "activity",
    "id": "j84",
    "verb": "place",
    "published_at": "1985-07-02T12:00:00.000000Z",
    "starts_at": null,
    "ends_at": null,
    "headline_template": ":actor placed :object with :target",
    "headline": null,
    "bindings": null,
    "glyph": null,
    "glyph_intent": null,
    "actor": {
      "type": "user",
      "id": "113",
      "label": "Erica Sinclair",
      "link": null,
      "data": [],
      "media": {
        "icon": null,
        "image": null,
        "preview": null,
        "initials": "ES",
        "color": "#be123c",
        "files": [],
        "slots": []
      },
      "media_ref": "maa7c0cfb07af83e2",
      "entity_ref": "ebe52ab4d5e63692e",
      "body": null,
      "tombstone": null
    },
    "object": {
      "type": "order",
      "id": "1035",
      "label": "Order #1035",
      "link": null,
      "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": null,
      "data": [],
      "media": {
        "icon": null,
        "image": null,
        "preview": null,
        "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
  }
]

Rendering the Feed ​

Install the Blade kit:

bash
composer require storyfeed/ui

Install the Tailwind CSS Typography plugin, which the kit uses for formatted text:

bash
npm install -D @tailwindcss/typography

Register the plugin and the kit's Tailwind CSS v4 utilities:

resources/css/app.css
css
@plugin "@tailwindcss/typography";
@source "../../vendor/storyfeed/ui/resources/views";

Return a view from the route:

routes/web.php
php
use Illuminate\Support\Facades\Route;
use Storyfeed\Facades\Storyfeed;

Route::get('/', function () {
    return view('feed', ['page' => Storyfeed::feed()->get()]);
});

Render the page in the view and load your application's CSS:

resources/views/feed.blade.php
blade
<!DOCTYPE html>
<html lang="en">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    @vite('resources/css/app.css')
</head>
<body>
    <x-storyfeed::feed :page="$page" />
</body>
</html>

Compile the CSS with npm run build. The feed displays the order placement:

ES
Erica Sinclair placed Order #1035 with Scoops Ahoy

For Inertia applications, use the Vue or React kit.

To keep a model's headlines in a class of their own, see Story Classes.

Released under the MIT License.