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 Deletions ​

Introduction ​

A manager deletes a menu item that was ordered for months. The menu item's activities still matter: the shop's history should keep showing what was sold and when. If the model is gone and nothing was recorded, the feed shows broken rows or loses them, with no sign the item was deleted.

Publish a delete activity before deleting its model. The activity remains, with a tombstone in place of the model. The tombstone records the model's former type and deletion time.

Recording a Deletion ​

app/Http/Controllers/MenuItemController.php
php
<?php

namespace App\Http\Controllers;

use App\Models\Menu;
use App\Models\MenuItem;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Storyfeed\Facades\Storyfeed;

class MenuItemController
{
    public function destroy(Request $request, Menu $menu, MenuItem $menuItem): RedirectResponse
    {
        Storyfeed::activity()
            ->by($request->user())
            ->action('delete', $menuItem)
            ->to($menu)
            ->publish();

        $menuItem->delete();

        return back();
    }
}
php
<?php

namespace App\Http\Controllers;

use App\Models\Menu;
use App\Models\MenuItem;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Storyfeed\Facades\Storyfeed;

class MenuItemController
{
    public function destroy(Request $request, Menu $menu, MenuItem $menuItem): RedirectResponse
    {
        Storyfeed::record(
            verb: 'delete',
            object: $menuItem,
            actor: $request->user(),
            target: $menu,
        );

        $menuItem->delete();

        return back();
    }
}
routes/feed.php
php
use App\Models\MenuItem;
use Storyfeed\Facades\Story;

Story::for(MenuItem::class)
    ->verb('delete')
    ->headline(':actor deleted :object from :target');
Steve Harrington
Steve Harrington deleted a removed menu item from Scoops Ahoy

delete is a removal verb, so the tombstone does not make its activity redundant.

Choosing What Stays ​

Other activities involving the menu item also remain with its tombstone. See Deleted Models for their headlines and payloads.

ToUse
keep the deleted model's label in earlier activitieskeepLabel() on its tombstone
remove activities made redundant by permanent deletionforgetWhenMissing() on those verbs
remove all activities involving a model, such as when a customer asks to be forgottendeleteFromFeed() or forceDeleteFromFeed() before deleting the model

Released under the MIT License.