Skip to content
Available for new work
Pages in Blog

ReferencePremium

Events and contracts in CoullWorks Blog for Laravel

How the package's typed events behave, which are vetoable, and the contracts you can bind to change its behaviour.

Updated 16 November 2026Back to the package pageBuy

Events#

Every extension event is a typed class. Listen to the class, never to a name.

  • A name ending in ing (for example PostSaving) is dispatched synchronously before the change and is vetoable: it implements Blockable, and a listener calls $event->block('reason') to stop the change and roll its transaction back. AiPromptBuilding is the one older hook that can only append text.
  • A name ending in ed, and the other past-tense or noun events, is dispatched after the surrounding database transaction commits, so a listener never sees a change that was rolled back.
  • A payload holds ids or models, never a licence key, a secret or a client address.
  • During an import the package defers its cache bumps and search updates to the end of the run. The import module's own events still fire per record.
php
use CoullWorks\Blog\Core\Events\PostPublishing;
use Illuminate\Support\Facades\Event;

Event::listen(function (PostPublishing $event) {
    if ($event->post->blog_id === 2) {
        $event->block('Posts on this blog are published by the editorial team only.');
    }
});

Events by module#

ModuleEvents
CoreAuthorSaving, AuthorSaved, AuthorDeleting, AuthorDeleted, the same four for Blog, Category and Tag, PostSaving, PostSaved, PostPublishing, PostPublished, PostUnpublished, PostDeleting, PostDeleted, PostDuplicated, RedirectCreated, RedirectUpdated, RedirectDeleted, RedirectRuleCreated, RevisionCreated, RevisionRestored, SettingChanged, TranslationAdded, TranslationPersisted, ImageStored, LicenceStatusChanged, CacheTagBumped, SearchIndexTouched, ContentAccessDenied
BlocksBlockDocumentSaving, BlocksIndexed, BlocksUpgraded
CommentsCommentSubmitting, CommentSubmitted, CommentApproved, CommentRejected, CommentMarkedSpam, CommentEditing, CommentEdited, CommentDeleting, CommentDeleted, CommentsClosedChanged, StaffReplied, ReplyNotificationsStopped
AnalyticsPostViewed, RelatedRefreshed
ImportImportStarted, ImportRecordImporting, ImportRecordImported, ImportFinished
AIAiRunStarting, AiRunFinished, AiDraftCreated, AiPromptBuilding, AiQueueItemStarting, AiQueueItemChanged, AiQueueItemFinished

ContentAccessDenied names what was refused and whether somebody was signed in, never who. A listener can log or count it; it cannot change the answer.

Contracts#

A contract is an interface your application can bind or implement.

ModuleContracts
CoreAuthorProvider, BlogResolver, ContentAccess, ContentValidator, LicenceChecker, PathPatterns, PostExtra, PostExtraProvider, Sanitiser, SearchEngine, SeoBatchContributor, SeoContributor, Urls
BlocksBlockType, ConsentChecker, ProductProvider, ProductRuleProvider (optional), HasNotices (optional)
ApiPayload
CommentsSpamVerifier
FilamentPanelExtension, PostEditorSection, SettingsSection
ImportDnsResolver, ImportSource
AiAiProvider, MakesImages, ResearchesWeb, WritesStructured

Restricting who can see content#

ContentAccess is the one gate. By default everyone sees every published post, category and listing. Bind your own class and the whole package follows it:

php
$this->app->bind(ContentAccess::class, PlanContentAccess::class);

It has four methods:

MethodAnswers
allows(?Authenticatable $viewer, AccessSubject $subject): boolMay this viewer see one post, one category or one kind of listing?
constrain($query, ?Authenticatable $viewer, AccessKind $kind, string $table): voidNarrow a post or category query so listings stay filtered in SQL
varies(): boolTrue when the answer depends on the viewer. Default false
denied(Request $request, AccessSubject $subject)Your own reply to a denied request, or null for the default 404

The contract can only narrow: a draft, scheduled, archived or inactive item stays hidden whatever your rule answers. The sitemap, feeds and API are anonymous. The package stores no audience data, so the rule reads whatever your application already has (roles, plans, your own tables). The viewer is read from the guard named in coullworks-blog.access.guard.

Available for new work

UK based · PHP · Python · JS · TS. Every first call is free.