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

Activities Without an Actor ​

Introduction ​

A restaurant's app records what people do, but some things happen with no person behind them. A nightly job closes the day's orders, a payment provider confirms a charge, and someone opens a link that was emailed to a supplier. The owner reading the feed wants to know who or what did each thing. If every one of these is recorded with an empty actor, the feed can't tell the nightly job from a stranger.

Use the user as actor for a person's action and a named party for a system's action. An anonymous activity has no recorded actor: who acted is unknown, including when you deliberately use Storyfeed::anonymous() or by(null).

Choosing an Actor ​

EventActorHeadline
a user places an orderthe user:actor placed :object with :target
a job, command, or integration marks an order paida named party:actor marked :object paid
an order expires without a recorded actornone:object expired at :target
someone fetches a link sent to a customernone; the customer is the target:object was fetched through the link sent to :target

Recording a System Actor ​

Pass a string to by() to record a named party, such as the payment service that confirmed the payment:

app/Jobs/MarkOrderPaid.php
php
<?php

namespace App\Jobs;

use App\Models\Order;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Storyfeed\Facades\Storyfeed;

class MarkOrderPaid implements ShouldQueue
{
    use Queueable;

    public function __construct(public Order $order) {}

    public function handle(): void
    {
        $this->order->update(['status' => 'paid']);

        Storyfeed::activity()
            ->by('Stripe')
            ->action('pay', $this->order)
            ->publish();
    }
}
php
<?php

namespace App\Jobs;

use App\Models\Order;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Storyfeed\Facades\Storyfeed;

class MarkOrderPaid implements ShouldQueue
{
    use Queueable;

    public function __construct(public Order $order) {}

    public function handle(): void
    {
        $this->order->update(['status' => 'paid']);

        Storyfeed::record(
            verb: 'pay',
            object: $this->order,
            actor: 'Stripe',
        );
    }
}

Define the headline for the verb:

routes/feed.php
php
use App\Models\Order;
use Storyfeed\Facades\Story;

Story::for(Order::class)->verb('pay')
    ->headline(':actor marked :object paid');
S
Stripe marked Order #1035 paid

Recording No Actor ​

To record no actor, such as for an order that expires unpaid, call Storyfeed::anonymous() and define a headline without :actor. See Recording Anonymous Activities.

A signed link proves which link was used, not who used it: a forwarded link or a mail scanner fetches it too. Record the fetch with no actor, and the intended recipient as the target:

routes/feed.php
php
use App\Models\Document;
use Storyfeed\Facades\Story;

Story::for(Document::class)->verb('fetch')
    ->headline(':actor fetched :object')
    ->anonymousHeadline(':object was fetched through the link sent to :target');
app/Http/Controllers/DocumentLinkController.php__invoke()
php
use Storyfeed\Facades\Storyfeed;

Storyfeed::anonymous()
    ->action('fetch', $document)
    ->to($recipient)
    ->data(['prefetch' => $request->header('Purpose') === 'prefetch'])
    ->publish();
php
use Storyfeed\Facades\Storyfeed;

Storyfeed::record(
    verb: 'fetch',
    object: $document,
    target: $recipient,
    anonymous: true,
    data: ['prefetch' => $request->header('Purpose') === 'prefetch'],
);
the Scoops Ahoy employment contract was fetched through the link sent to Erica Sinclair

scoops-ahoy-employment-contract.pdf PDF · 48 KB

Storyfeed::feed()->involving($recipient) lists the fetches through their links. A Purpose: prefetch header hints that software fetched the link, so it is stored as data, never as the actor.

Released under the MIT License.