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

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:

app/Models/Order.php
php
<?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.

SourceExample
name attributeUSS Butterscotch
title attributeSpring Menu
class name and keyOrder #1042
ES
Erica Sinclair placed Order #1035 with Scoops Ahoy

Customizing Model Labels ​

To set a model's label, define its 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}", 
        );
    }
}
ES
Erica Sinclair placed Order #1035 with Scoops Ahoy

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.

Released under the MIT License.