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

Recording an Authoriser ​

Introduction ​

A junior chef changes the menu, and the head chef approves it before it goes live. The feed should credit the junior chef with the change. The owner still needs to answer who approved it. Recording the head chef as the actor hides who did the work, and leaving the approval out loses it.

When one person acts and another approves, keep the person who acted as the activity's actor. Record approval separately and exclude it from displayed feeds so you can still query who approved. If the model already stores the approver in a column or status field, use that record.

Recording an Approval ​

routes/feed.php
php
use App\Models\Photo;
use Storyfeed\ActivityStreams\ActivityType;
use Storyfeed\Facades\Story;

Story::for(Photo::class)->verb('approve')
    ->type(ActivityType::Accept)
    ->headline(':actor approved :object'); // needed even when feeds leave it out

Story::for(Photo::class)->verb('publish')
    ->headline(':actor published :object to :target');
app/Http/Controllers/ApprovePhotoController.php
php
<?php

namespace App\Http\Controllers;

use App\Models\Photo;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Storyfeed\Facades\Storyfeed;

class ApprovePhotoController
{
    public function __invoke(Request $request, Photo $photo): RedirectResponse
    {
        Storyfeed::activity() // the contributor's activity
            ->by($photo->user)
            ->action('publish', $photo)
            ->to($photo->menuItem)
            ->publish();

        Storyfeed::activity() // the approval; exclude its verb from displayed feeds
            ->by($request->user())
            ->action('approve', $photo)
            ->publish();

        return back();
    }
}
php
<?php

namespace App\Http\Controllers;

use App\Models\Photo;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Storyfeed\Facades\Storyfeed;

class ApprovePhotoController
{
    public function __invoke(Request $request, Photo $photo): RedirectResponse
    {
        Storyfeed::record( // the contributor's activity
            verb: 'publish',
            object: $photo,
            actor: $photo->user,
            target: $photo->menuItem,
        );

        Storyfeed::record( // the approval; exclude its verb from displayed feeds
            verb: 'approve',
            object: $photo,
            actor: $request->user(),
        );

        return back();
    }
}

Filtering Approval Activities ​

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

Storyfeed::feeds([
    'shop' => fn (FeedBuilder $feed) => $feed->only(['publish', 'reprice']),
]);

The shop feed includes only publish and reprice, excluding approvals. For a feed without only(), call except('approve').

Use this for moderation, approval by a second person, or drafts released by someone else. Separate activities preserve each person's role and let you find the approval with involving().

Finding the Approver ​

In your controller or view model, retrieve the photo's latest approve activity in log mode. Its actor is the approver:

Where the approver is shown: a controller or a view model
php
use Storyfeed\Facades\Storyfeed;

$approval = Storyfeed::feed()
    ->involving($photo)
    ->verb('approve')
    ->log()
    ->limit(1)
    ->get()
    ->first();

$approvedBy = $approval?->actor()?->label();
$approvedAt = $approval?->publishedAt();

ActivityType::Accept maps the approval to Activity Streams Accept. The contributor remains the actor of the publication activity.

Displaying Approvals ​

Display the approver's name and approval time under the published activity. The lookup requires one query per photo, so for long lists, also copy the approver's name into the published activity's data. Keep the approval activity as the original record.

Recording Connected App Writes ​

When an operator writes through a connected app, see Recording Connected App Writes.

Released under the MIT License.