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

Package Integration ​

Introduction ​

Ship activity definitions from your Laravel package's service provider. Applications can use them without creating a feed file.

Registering Stories in a Service Provider ​

A service provider can register stories without a feed file:

A package service provider
php
<?php

namespace Vendor\Orders;

use Illuminate\Support\ServiceProvider;
use Storyfeed\Facades\Story;
use Storyfeed\Grouping\GroupBuilder;

class OrderFeedServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        Story::for('order')
            ->verb('place')
            ->headline(':actor placed :object with :target')
            ->icon('shopping-bag')
            ->grouped(
                fn (GroupBuilder $group) => $group
                    ->repeat(':actor made :count order placements with :target'),
            );
    }
}
Erica Sinclair

The string order is the model's morph alias. Using the alias lets a package register its stories before the application registers its morph map.

Provider registrations remain available when the configured definitions file is missing or definitions is false. They are included when caching definitions. The repeat headline applies to grouped orders.

Overriding a Package's Stories ​

In this example, an installed package defines the place verb for order activities with the headline :actor placed :object with :target, a shopping-bag icon, and the repeat-group headline :actor made :count order placements with :target. To change only its single-activity headline, declare an explicit override:

routes/feed.php
php
use Storyfeed\Facades\Story;

Story::for('order')
    ->verb('place')
    ->override()
    ->headline(':actor submitted :object to :target');
Erica Sinclair

Only the headline changes. The package's shopping-bag icon and repeat-group headline remain. Its Story class binding also remains when the application supplies only presentation fields.

For presentation fields, override() applies to the same object type and verb. It takes precedence over the original declaration regardless of registration order. Wildcard precedence still applies between different keys.

Supplied OptionWhat Changes
Headline, anonymous headline, icon, or intentthat value
Group headlineseach supplied axis headline; other axes remain
Castseach supplied data key; other keys remain
Role constraintseach supplied role; other roles remain
Queue optionseach supplied option; other options remain
Middleware, missing-role policy, or keep-latest policythe whole supplied property

Ordinary declarations from different source locations that claim the same headline or icon key cause an error, even if their values are identical. Explicit overrides from different source locations that claim the same field and key also cause an error. Caching still requires unique story names.

Released under the MIT License.