Skip to main content

History (Audit Log) — Backend Documentation

Overview

The platform keeps a lightweight audit trail of CRUD-style actions in the history table. Whenever a controller performs a tracked action it calls the global helper insert_in_history_table($action, $row_id, $table_name) (app/Helpers/helpers.php), which stamps a row with the acting user, a free-text action label, the affected row id and table name. This endpoint exposes that trail for reading:
Authentication: Bearer token required (Laravel Sanctum). Middleware: lives in the main tenant-scoped block — auth:sanctum, check_if_user_is_blocked_middleware, company_policy_middleware. Headers (for all requests):
Handled by SuperAdminController@index.

How It Works

  1. The request hits SuperAdminController@index.
  2. Query params are validated (pagination, filters, sorting).
  3. A history ↔ users left-join query is built, selecting the entry plus the user’s full name and email. Soft-deleted entries (deleted_at) are excluded.
  4. Visibility scoping is applied based on the caller’s role:
    • Admin / Super-Admin → can see everyone’s entries, and may filter by user_id.
    • Any other role (Student, Instructor, Content Manager) → forcibly restricted to their own entries; the user_id filter is ignored for them.
  5. Optional filters (table_name, row_id, search) are applied.
  6. Results are sorted and returned as a standard Laravel paginator.
Note: entries are not company-scoped in the query itself — visibility is driven by role + ownership as described above (admins see all rows).

The history Table


Query Parameters

All parameters are optional. Validation failures return 422 with Laravel’s standard validation error shape.

Response

Standard Laravel paginator. Each item in data includes the joined user info:

Postman Examples

1. Latest activity (defaults)

Returns the 20 most recent entries the caller is allowed to see (own entries for non-admins, everyone’s for admins).

2. Admin: a specific user’s actions

3. Filter by table + search the action text

4. Audit a single record


Notes & Gotchas

  • Role-based visibility is enforced server-side — a non-admin cannot read another user’s history even by passing user_id; that filter only applies to admins/super-admins.
  • Soft-deleted entries are hidden — rows with a deleted_at are never returned.
  • per_page is capped at 100 to protect the join query.
  • Entries are write-once via insert_in_history_table(...); this endpoint is read-only (no create/update/delete routes for history).
  • action is free-text, so search matches whatever label the calling controller chose to log — labels are not standardized across modules.