codetech/laravel-api-logs
A lightweight Laravel package that logs every authenticated API request — URL, method, IP, payload, headers, response, and duration — linked to the user who made it. Sensitive values are redacted before storage, and a HasApiLogs trait exposes each user's history.
Architecture fit
LogApiRequest) appended to the api group, one published migration, and an ApiLog Eloquent model with a polymorphic causer relation plus an opt-in HasApiLogs trait. It occupies the same integration surface as any first-party middleware — no service container overrides, no queue dependency, no external SaaS contract.terminate(), after the response is flushed. Architecturally correct (no user-facing latency in the happy path) but it means one synchronous INSERT against the primary database per authenticated request.api_logs table becomes your schema — while the model, casts, and effectively the column contract stay with the vendor. Any future column change becomes an upgrade-coordination event across teams.Integration feasibility
composer require, publish + run migrations, append middleware, add trait. For a team already on Laravel 11–13, half a day including verification.Authorization/Cookie/X-Api-Key/CSRF headers, response bodies (protecting token-issuing endpoints), and stored query strings. v3.1.0 shipped this; v2.1.0 backported it.response_data = null rather than corrupting the row.Technical risk
x_session, auth_code, free-text notes fields that happen to carry secrets) will persist in plaintext. This is the risk that needs an explicit owner, not a checkbox.Key questions
api_logs table a system of record for anything (audit, billing, incident forensics), or purely diagnostic? The answer sets the availability bar and the backup strategy.Stack fit
^2.0, which is in security-fix-only mode — a strong argument for upgrading the framework first rather than adopting the package on an old stack.HasApiLogs trait + $user->apiLogs relationship gives product-facing value immediately (support can browse a customer's request history without a DBA), which is often the real ROI versus raw log files.Migration path
api group; verify ordering relative to auth middleware, since logging depends on the authenticated principal being resolved. Where auth is resolved later in the stack, confirm duration and causer are still correct (v2.0.2 fixed a related defect).HasApiLogs to each participating model, in a single PR per model, with a test asserting rows appear.api group.Compatibility
Sequencing
Maintenance
Support
SECURITY.md with private disclosure and a CONTRIBUTING.md. Acceptable for open source, not a commercial SLA — there is no paid support tier, no response-time commitment, no LTS guarantee.Scaling
terminate() INSERT is the primary scaling constraint. It sits on the request path for connection/query budget even though it is off the response path. At high RPS, a full-payload table can dwarf the application's own core tables — payload + headers + response bodies per row is not a small row.response_data for high-volume endpoints. None of these are package features — they are your roadmap items.Failure modes
terminate() cannot fail a response that already went out, so gaps are invisible unless alerted on. Conversely, verify it can't surface as a 500 under unusual conditions (connection pool exhaustion).api_logs, and a causer polymorphic relation that will be orphaned when a user is deleted. Decide cascade behaviour up front.Ramp-up
How can I help you explore Laravel packages today?