# Add an Audit Log to a Filament Admin Panel

Yes. An agent installs spatie/laravel-activitylog, logs changes on your Filament resources' models, adds a read-only Activity resource, tests it, and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-audit-log/filament/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads how the panel is assembled before it logs anything. In an admin shaped like filamentphp/demo, `composer.json` requires `php ^8.1`, `laravel/framework ^12.0`, `filament/filament ^5.0` with the Spatie media library, settings and tags plugins, and in development `pestphp/pest ^3.0`, `larastan/larastan ^3.1`, `laravel/pint` and `rector/rector`, with scripts `test:pest` for `pest --parallel`, `test:phpstan` for `phpstan analyse` at level 8 over `app/`, and `cs` for Pint. `app/Providers/Filament/AdminPanelProvider.php` discovers resources under `app/Filament/Resources`, groups navigation into `Shop`, `HR`, `Projects` and `Blog`, and turns on database notifications and SPA mode. The resources are split per model, `Shop/Orders/OrderResource.php` with its `Schemas/OrderForm.php`, `Tables/OrdersTable.php` and `Pages/`, and the models under `app/Models/Shop`, `HR` and `Blog` use `HasFactory` and, on `Order` and `Customer`, `SoftDeletes`.

It adds `spatie/laravel-activitylog` with Composer, publishes its migration and config, and gives the models that matter the `LogsActivity` trait with `getActivitylogOptions()` set to `logOnly` the `$fillable` columns, `logOnlyDirty()` and `dontSubmitEmptyLogs()`: `Shop\Order`, `Shop\Product`, `Shop\Customer`, `Blog\Post` and `HR\Employee` in this run, chosen because their resources have edit pages. Because Filament's edit page saves through Eloquent, every change made in the panel is attributed to the signed-in `User` by the package's causer resolver, with no change to `OrderForm.php` or the pages.

A new `app/Filament/Resources/Activities/ActivityResource.php` over `Spatie\Activitylog\Models\Activity` lists `created_at`, `causer.name`, `subject_type`, `subject_id`, `event` and a `properties` column rendered as the changed attributes, with filters on `subject_type` and date, sorted newest first, and only a `ListActivities` page and a `ViewActivity` page, no create or edit. It sits in a new `Audit` navigation group added to the provider's `navigationGroups()`. The `canCreate`, `canEdit` and `canDelete` methods return `false`, so nothing in the panel can alter the log.

Tests follow `tests/Pest.php`, which extends `TestCase` with `RefreshDatabase` and signs in a factory user before each test in `tests/Filament`, and the shape of `tests/Filament/Resources/HR/Projects/Pages/EditProjectTest.php`: `Livewire::test(EditProject::class, ['record' => ...])->fillForm([...])->call('save')`. The new `tests/Filament/Resources/Activities/Pages/ListActivitiesTest.php` edits an order through `EditOrder`, asserts one `activity_log` row with the signed-in user as causer and the old and new values in `properties`, asserts the list page renders it with `assertCanSeeTableRecords`, and asserts the resource has no create page. The agent runs `composer test`, both Pest and PHPStan, and `composer cs` against the SQLite database the `tests` workflow uses, after `npm ci` and `npm run build` for the Vite theme.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add an audit log to this Filament admin panel and open a pull request. Read composer.json, phpstan.neon, app/Providers/Filament/AdminPanelProvider.php, app/Models/Shop/Order.php, app/Models/User.php, app/Filament/Resources/Shop/Orders/OrderResource.php and its Pages, tests/Pest.php, tests/Filament/Resources/HR/Projects/Pages/EditProjectTest.php and .github/workflows/tests.yml first. Require spatie/laravel-activitylog, publish its migration and config. Add the LogsActivity trait with logOnly of the fillable columns, logOnlyDirty and dontSubmitEmptyLogs to Shop\\Order, Shop\\Product, Shop\\Customer, Blog\\Post and HR\\Employee. Add app/Filament/Resources/Activities/ActivityResource.php over Spatie's Activity model with a list page and a view page only, columns for created_at, causer name, subject type and id, event and the changed properties, filters on subject type and date, newest first, canCreate, canEdit and canDelete returning false, in a new Audit navigation group registered in the panel provider. Add tests/Filament/Resources/Activities/Pages/ListActivitiesTest.php: editing an order through EditOrder writes one activity row with the signed-in user as causer and old and new values, the list page shows it, and the resource has no create page. Run npm ci, npm run build, composer test and composer cs and paste the output in the pull request. Do not change the existing resources' forms, tables or pages.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request with `spatie/laravel-activitylog` in `composer.json` and `composer.lock`, the published migration under `database/migrations` and `config/activitylog.php`, the trait on five models, `ActivityResource.php` with its two pages and table under `app/Filament/Resources/Activities`, a line in `AdminPanelProvider.php`, and the Pest test. The description lists which models are logged, shows one `activity_log` row from the test database, and includes the output of `pest --parallel`, `phpstan analyse` and Pint from the sandbox.

The repository's `tests` workflow runs `composer test:pest` on PHP 8.4 with SQLite after building the assets, and the `phpstan` workflow runs level 8 analysis, so the new resource's return types and the trait's generics are checked on the pull request.

A reviewer checks that only the five named models carry the trait, that `logOnlyDirty` keeps a no-op save from writing a row, that the resource exposes no create, edit or delete action, that the causer is the panel user and not null for console commands, and that the migration runs on their production database. Then they decide whether to add the remaining HR models.

## Run it on every admin panel that handles customer records

A team that runs a Filament panel per product sends one `POST /o/{org}/sessions` per repository with this prompt and that repository in `resources`, naming in `input` the models that carry customer data. Each run reads its own resources and panel provider, so a panel with tenancy gets the team scoped into the activity list, and each run opens its own pull request.

Give the API key a `webhook_url` and Rush POSTs `run.completed` when each turn ends, with the `session_url` to read the pull request from.

## Why run it on Rush?

An audit log in an admin panel is judged on one question: when a record changed, who did it and what was the old value. In a Rush sandbox the agent edits an order through the real `EditOrder` Livewire page in a test, reads the `activity_log` row back, and keeps that output with every `composer` and `npm` command in the run's record, so the pull request shows the row rather than describing it.

The demo runs Pest in parallel, PHPStan at level 8 and Pint on every push, and a Filament resource over a vendor model is exactly where generics and return types go wrong. The agent runs all three before pushing, and the same request works unchanged on the next Filament panel a team owns.

## Frequently asked questions

### Why spatie/laravel-activitylog rather than a custom table?

The panel already depends on three Spatie packages through Filament plugins, and `laravel-activitylog` records the causer, the subject and the old and new attributes with one trait, so the change to each model is five lines. A custom observer would reimplement that and need its own tests.

### Does it change the existing resources?

No. The trait goes on the models, and Filament's edit pages save through Eloquent, so `OrderForm.php`, `OrdersTable.php` and the pages are untouched. The only resource file added is the new `ActivityResource`.

### Can an admin delete log entries?

Not from the panel. The resource returns `false` from `canCreate`, `canEdit` and `canDelete` and registers only list and view pages, and the test asserts there is no create page. Pruning old rows is the package's `activitylog:clean` command, run from a schedule if the team wants it.

### What about changes made outside the panel?

The trait logs every Eloquent save, so a seeder or a console command writes rows too, with no causer. The pull request notes this so the team can decide whether to disable logging during seeding with the package's `activity()->disableLogging()`.

## More Filament jobs

- [Add a Blog Dashboard to a Filament Admin Panel from a Linear Issue](https://getrush.ai/run/add-blog-dashboard/filament/)
- [Add a Bulk Export Action to a Filament Table from a Linear Issue](https://getrush.ai/run/add-bulk-export/filament/)
- [Add Test Coverage to CI for a Filament App](https://getrush.ai/run/add-coverage-to-ci/filament/)

## The same job on other stacks

- [Add an Audit Log to a Mongoose and Express API](https://getrush.ai/run/add-audit-log/mongoose/)
- [Add an Audit Log to a Prisma Project](https://getrush.ai/run/add-audit-log/prisma/)
- [Add an Audit Log to a Quarkus API](https://getrush.ai/run/add-audit-log/quarkus/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
