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
| Event | Actor | Headline |
|---|---|---|
| a user places an order | the user | :actor placed :object with :target |
| a job, command, or integration marks an order paid | a named party | :actor marked :object paid |
| an order expires without a recorded actor | none | :object expired at :target |
| someone fetches a link sent to a customer | none; 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:
<?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
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:
use App\Models\Order;
use Storyfeed\Facades\Story;
Story::for(Order::class)->verb('pay')
->headline(':actor marked :object 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 Link Sent to Someone
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:
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');use Storyfeed\Facades\Storyfeed;
Storyfeed::anonymous()
->action('fetch', $document)
->to($recipient)
->data(['prefetch' => $request->header('Purpose') === 'prefetch'])
->publish();use Storyfeed\Facades\Storyfeed;
Storyfeed::record(
verb: 'fetch',
object: $document,
target: $recipient,
anonymous: true,
data: ['prefetch' => $request->header('Purpose') === 'prefetch'],
);scoops-ahoy-employment-contract.pdf
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.