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

Custom Axes ​

Group activities by shared fields and choose which custom group takes priority.

Defining Custom Axes ​

Define a custom axis with the fields activities must share and the threshold they must meet:

app/Providers/AppServiceProvider.phpboot()
php
use Storyfeed\Facades\Storyfeed;
use Storyfeed\Grouping\Axis;

$scene = Axis::make('scene')
    ->key('v:ca!:cid!:d')
    ->eligibleWhenDistinct('actor', min: 2);

Storyfeed::axes([$scene]);

Activities published from now on are grouped on the new axis. To apply it to stored activities, rehash them:

bash
php artisan storyfeed:curate --rehash

Here, scene groups activities in the same context, such as three customers asking about dishes in one shop. Use $group->axis('scene', …) inside grouped() to define its headline, or $group->any(…) to match any axis.

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

Story::verb('ask')->grouped(fn (GroupBuilder $group): GroupBuilder => $group
    ->axis('scene', ':actors asked questions in :context')
    ->actorsOnTarget(':actors asked about :target'));

Two customers sharing a context meet this axis's threshold but not the built-in actors_target threshold, so the query returns a scene group:

Robin BuckleyDustin Henderson
Robin BuckleyDustin Henderson

Axis Keys ​

Separate shared fields with :. Add ! after a field to exclude activities where it is empty.

RoleType FieldId Field
actoraaaid
objectoaoid
targettatid
contextcacid
originoraorid
resultrarid
instrumentiaiid
locationlalid
generatorgagid

See Default Grouping Keys for the built-in axes.

Built-in axes assign their keys to persisted bursts. Custom axes may add v to group by verb and d to group by calendar period (a day by default). A singular token such as :context requires both of that role's fields in the key. Without v, the group may contain several verbs, so define its headline on Story::fallback(), which applies to every verb:

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

Story::fallback()->grouped(fn (GroupBuilder $group): GroupBuilder => $group
    ->axis('visits', ':actors were busy in :context'));

Here, visits is an axis registered with the key ca!:cid!:d.

Calendar Periods ​

Calendar declarations such as groupedWeekly() apply to custom axes whose keys include the calendar field d. Built-in Live axes use burst windows.

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

Story::verb('ask')->groupedWeekly();

The scene key above includes d, so this declaration groups each week's questions separately. Calendar boundaries use the application's timezone.

Prioritizing Axes ​

With three customers, both actors_target and scene qualify. The built-in actors_target axis has priority and selects the group:

Robin BuckleyDustin Henderson
Robin BuckleyDustin HendersonErica Sinclair

New axes have the lowest priority among selectable axes. To put scene before actors_target, reuse the $scene defined above:

app/Providers/AppServiceProvider.phpboot()
php
use Storyfeed\Facades\Storyfeed;

Storyfeed::axes([$scene], before: 'actors_target');

After group selection runs with this priority, the same activities form a scene group that names their shared context:

Robin BuckleyDustin Henderson
Robin BuckleyDustin HendersonErica Sinclair

Released under the MIT License.