Skip to content

Artisan commands

Most applications schedule one command, views:maintain, which rolls up, anonymises and deletes old views and recounts counter columns as the config asks. Add views:flush with the Redis buffer, views:pairs with the pairs table and views:detect-spikes with spike alerts.

routes/console.php
Schedule::command('views:maintain')->hourly()->onOneServer();

Take what ties a view to a person out of old views. See the docs and the source.

Terminal window
php artisan views:anonymise
Argument or option Description
--older-than= Anonymise views older than this, such as 30d, instead of retention.anonymise.after
--chunk= How many views to anonymise per statement
--max-seconds= Stop starting new chunks after this many seconds, the next run carries on
--dry-run Count the views that would be anonymised without changing them

Compare the last closed window of the watched models with their past, and dispatch an event when one spikes, drops or settles. See the docs and the source.

Terminal window
php artisan views:detect-spikes

Write a migration that adds a column for every dimension the views table lacks. See the docs and the source.

Terminal window
php artisan views:dimensions
Argument or option Description
--backfill= Copy the values of this dimension from context into its column
--from= The JSON path to copy from, context->{name} by default
--max-seconds= Stop starting new chunks of the backfill after this many seconds

Check the setup of the package and say what to fix. See the docs and the source.

Terminal window
php artisan views:doctor
Argument or option Description
--only= Run only the checks with these keys, such as schema Repeatable.
--json Print the findings as JSON
--strict Fail on warnings as well as failures

Land the views the configured store has buffered in the views table. See the docs and the source.

Terminal window
php artisan views:flush
Argument or option Description
--batch= How many views to land per insert Default 1000.

Delete every view of one viewer. See the docs and the source.

Terminal window
php artisan views:forget-viewer <type> <id>
Argument or option Description
type The model class or morph alias of the viewer, such as “App\Models\User”
id The key of the viewer, which may already be deleted
--with-visitors Also delete the guest views of the browsers the viewer was signed in on
--chunk= How many views to delete per statement
--force Delete without asking in production

Delete every view of one visitor. See the docs and the source.

Terminal window
php artisan views:forget-visitor <visitor>
Argument or option Description
visitor The visitor id, the value of the visitor cookie
--chunk= How many views to delete per statement
--force Delete without asking in production

Roll up, anonymise and delete old views and recount counter columns as configured. See the docs and the source.

Terminal window
php artisan views:maintain
Argument or option Description
--chunk= How many views to change per statement
--max-seconds= Stop starting new work after this many seconds, the next run carries on
--dry-run Count the views that would change without changing them

Rewrite the pairs table that alsoViewed() and recommended() read. See the docs and the source.

Terminal window
php artisan views:pairs
Argument or option Description
--period= Pair only this one of the configured periods, such as 30d

Delete old views. See the docs and the source.

Terminal window
php artisan views:prune
Argument or option Description
--older-than= Delete views older than this, such as 90d, instead of retention.prune.after
--before= Delete views viewed before this date, such as the start of a dropped partition
--chunk= How many views to delete per statement
--max-seconds= Stop starting new chunks after this many seconds, the next run carries on
--dry-run Count the views that would be deleted without deleting them

Delete the views of bots that opened many models within seconds. See the docs and the source.

Terminal window
php artisan views:purge-bots
Argument or option Description
--since= How far back to look, a duration such as 7d or a date such as 2026-01-01 Default 1d.
--max= More than this many different models within –seconds is a burst, instead of recording.bursts.max
--seconds= The window of a burst, instead of recording.bursts.seconds
--whole-visitor Delete every view of a visitor with –min-bursts separate bursts, not only the views in a burst
--min-bursts= How many separate bursts –whole-visitor needs Default 3.
--include-viewers Also delete views of a signed-in viewer
--chunk= How many views to read and delete per statement
--dry-run Count the views that would be deleted without deleting them
--force Delete without asking in production

Write the view counts of the configured counter columns. See the docs and the source.

Terminal window
php artisan views:recount
Argument or option Description
--chunk= How many models to recount per statement
--max-seconds= Stop starting new chunks after this many seconds, the next run carries on
--full Recount every model, not only those whose counts can have changed

Fold the views of closed buckets into the rollup tiers and expire old tiers. See the docs and the source.

Terminal window
php artisan views:rollup
Argument or option Description
--tier= Fold only this tier: hour, day, month or year
--rollup= Fold only the rollup of this name, views for the built-in one
--from= Fold again from this date instead of where the last run stopped
--chunk= How many expired rollup rows to delete per statement
--max-seconds= Stop starting new buckets after this many seconds, the next run carries on
--dry-run Count the buckets that would be folded without folding them

Mark every model at its current count, so the milestones it already passed never fire. See the docs and the source.

Terminal window
php artisan views:seed-milestones [model]
Argument or option Description
model The model class or morph alias to seed, every configured one when left out Optional.