rigosv/audit-bundle
An audit bundle for Laravel that records model and application activity for traceability. Logs changes with user context so you can review who did what and when, supporting compliance and debugging across your PHP projects.
v0.1.9 is a small, additive release ("Session id added") with no deprecations or breaking changes signalled, so upgrading from v0.1.8 should be a no-op beyond a composer update. Because the package is still on a 0.x line, treat minor bumps as potentially breaking by convention and pin explicitly: "vendor/package": "^0.1.9".
Minimal setup:
composer require vendor/package:^0.1.9php artisan about or check bootstrap/cache/packages.php). If the package is not discovery-friendly, register the provider manually in bootstrap/providers.php.php artisan vendor:publish --provider="Vendor\\Package\\PackageServiceProvider"
The two things worth reading first are the published config file (to see whether session id capture is opt-in) and any migration (to confirm the new column is nullable on existing tables).php artisan config:clear && php artisan optimize:clear.Your first use case should be the smallest possible: hit a stateful web route, then inspect the record/log entry the package produces and confirm a non-null session id. If it is null on a route you expect to be stateful, the problem is almost always middleware ordering or a stateless route — see below.
Verify middleware position. Session id only exists after Laravel's StartSession middleware has run. If the package ships its own middleware, place it after the web group (or explicitly after StartSession) in bootstrap/app.php:
->withMiddleware(function (Middleware $middleware) {
$middleware->web(append: [
\Vendor\Package\Middleware\CaptureContext::class,
]);
})
Correlate logs with the session id. The main day-to-day value of this release is traceability. Push the session id into log context once per request (a Monolog processor or a small middleware) so every line in a request's lifetime is greppable:
Log::withContext([
'session_id' => $request->hasSession() ? $request->session()->getId() : null,
]);
Guard for session-less contexts. Console commands, queued jobs, health checks, and api-guarded routes have no session. Resolve the value defensively rather than assuming a string:
$sessionId = $request->hasSession() ? $request->session()->getId() : null;
Pass it forward explicitly. When dispatching a job from a request, copy the session id onto the job payload if you need end-to-end tracing; the queue worker does not inherit session state.
Test it. Feature tests using $this->actingAs($user) or $this->withSession([...]) will produce a session id; tests hitting stateless endpoints will not. Assert both cases so the null path stays covered:
$response->assertSessionHasNoErrors();
$this->assertNotNull(session()->getId());
Prefer the package's resolver over reaching into the session directly. If the package exposes a config-driven resolver or a container binding for the current context, bind a fake in tests rather than mocking Session — it keeps test setup aligned with how production resolves the value.
Auth::login() and $request->session()->regenerate() mint a new id. Capture the value late (in a terminating middleware or Terminating/JobProcessed-style hook) if you need the id that is actually persisted to the cookie.session()->getId() before StartSession is a different id (or throws on a store with no started session). Middleware order is the number one cause of "session id is null/empty" reports.api guards never have a session. Don't make the new column non-nullable, and don't let downstream code assume a string.array session driver does not persist across requests; withoutMiddleware(StartSession::class) in a test will silently remove the session id and produce confusing assertions.ALTER with a default.php artisan config:cache must be re-run or the old values persist — a very common cause of "the feature is enabled locally but not in staging".php artisan route:list -v (middleware stack), php artisan tinker with session()->getId(), and php artisan config:show vendor-package to confirm the published config is actually loaded.0.x line, the smallest-looking release can precede a rename of the session id accessor; a thin internal wrapper around the package's API will keep that upgrade cheap.How can I help you explore Laravel packages today?