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
<?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
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();
}
}use App\Models\MenuItem;
use Storyfeed\Facades\Story;
Story::for(MenuItem::class)
->verb('delete')
->headline(':actor deleted :object from :target');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.
| To | Use |
|---|---|
| keep the deleted model's label in earlier activities | keepLabel() on its tombstone |
| remove activities made redundant by permanent deletion | forgetWhenMissing() on those verbs |
| remove all activities involving a model, such as when a customer asks to be forgotten | deleteFromFeed() or forceDeleteFromFeed() before deleting the model |