Feedable Models
Introduction
A feedable model provides a label for its activities. Storyfeed supplies a default label; links and images are optional. Making a model feedable does not record activities.
For a model from another package, such as Spatie Media Library, see Registering External Models. To implement the contract's methods yourself, see Implementing the Feedable Contract. To retrieve a model's activities, see Filtering by Entity or Role.
Making Models Feedable
Using Default Labels
Implement the Feedable interface and use the InteractsWithFeed trait:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Storyfeed\Concerns\InteractsWithFeed;
use Storyfeed\Contracts\Feedable;
class Order extends Model implements Feedable
{
use InteractsWithFeed;
}Without any configuration, Storyfeed guesses a model's feed label by checking commonly used columns, falling back on the class name and key.
| Source | Example |
|---|---|
name attribute | USS Butterscotch |
title attribute | Spring Menu |
| class name and key | Order #1042 |
Customizing Model Labels
To set a model's label, define its 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}",
);
}
}The toFeed method returns a FeedEntity containing the model's label. Set the label on the returned entity when you implement this method. InteractsWithFeed refreshes the shared snapshot on model saves while recording is enabled. Changes to its label, body, or data can therefore appear on older activities too. Activity data preserves the values recorded for that event.
You may also customize default labels across your application.
To add snapshot values while retaining a default label, use describeFeed().
Linking Models and Showing Media
Use feedMedia() to resolve a model's links, files, pictures, and actor avatar when the feed is retrieved. See Feed Media for each job and its feed outcome.
For stored resolver inputs, see Storing Snapshot Data.
Storyfeed is headless: it has no views
Storyfeed serializes the feed as a structured payload, and your frontend chooses how to render it. For Blade, Storyfeed UI renders it with one component.