testmonitor/laravel-accountable
Laravel package that makes Eloquent models accountable by tracking which user created, updated, or deleted each record. Adds configurable audit relations and helpers so you can see who did what, when, and query models by responsible user.
created_by / updated_by on models) is the cheapest way to answer "who changed this?" for support, internal audit, and regulatory asks (SOC 2, GDPR data provenance, HIPAA-adjacent workflows). The 10.1.0 release moves it from "convenient default" to "production-grade audit primitive."system, a specific integration user, or an upstream owner rather than the currently authenticated actor. This is a common compliance requirement ("this record was created by the API, not by Jane in support").whileActingAs callback helper gives you a bounded context in which writes are attributed to a chosen user. Relevant product surfaces: admin "act as customer" tooling, queue/console jobs that have no auth context, replay/reprocessing flows, and support-driven corrections. Preferring a callback over global state reduces the risk of attribution leaking into unrelated writes in the same request or job.Adopt when:
created_by / updated_by (and optionally deleted_by) with minimal boilerplate.null or accidental.Auth::login() swap.Look elsewhere or supplement when:
To executives: We're standardizing how our application records who created and changed each record. This release closes two gaps that previously forced custom code or left audit data unreliable: records can now carry an intentional author (imports and migrations keep their original attribution instead of being misattributed to whoever ran the job), and we can safely attribute actions to a specific user inside a bounded scope — for example, an automated job or a support "act as" session — without that attribution bleeding into other work. Net effect: stronger audit posture for compliance and customer security questionnaires, less bespoke code to maintain, and faster delivery of admin and bulk-operation features.
To engineering: 10.1.0 is additive and non-breaking. Two capabilities: (1) explicitly set userstamps are no longer overwritten, so Model::create([... 'created_by' => $id]) and import/backfill paths preserve authorship; (2) whileActingAs($user, fn () => ...) provides callback-scoped attribution — preferred over swapping the authenticated user globally, since it's exception-safe and contained to the closure. Adopt it for queued jobs and console commands where Auth is empty, and for impersonation features. Note the boundaries: this stamps identity only — no before/after diffs, no immutable log, no cross-service contract. If audit is a product requirement rather than a convenience, pair it with a change-history/append-only log and treat the stamp columns as the "who," not the "what."
Migration note: additive minor release; verify any existing code that relied on stamps being overwritten (rare, but check import and seeder paths), and confirm the whileActingAs helper's nesting and exception behavior matches your impersonation policy before shipping admin tooling on it.
How can I help you explore Laravel packages today?