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:
<?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
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:
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:
use Storyfeed\Facades\Storyfeed;
Storyfeed::activity()
->by($customer)
->action('place', $order)
->to($shop)
->publish();use Storyfeed\Facades\Storyfeed;
Storyfeed::record(
verb: 'place',
object: $order,
actor: $customer,
target: $shop,
);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:
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:
composer require storyfeed/uiInstall the Tailwind CSS Typography plugin, which the kit uses for formatted text:
npm install -D @tailwindcss/typographyRegister the plugin and the kit's Tailwind CSS v4 utilities:
@plugin "@tailwindcss/typography";
@source "../../vendor/storyfeed/ui/resources/views";Return a view from the route:
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:
<!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:
For Inertia applications, use the Vue or React kit.
To keep a model's headlines in a class of their own, see Story Classes.