Testing and Tooling
Cache and about
Cache the control of each model with access:cache in every deployment, and read the state of the package in the Access Control section of php artisan about.
Caching the controls
php artisan access:cache
php artisan access:clear
access:cache writes the control of each discovered model, and the models that the reindexWhen() rules of the controls watch, into bootstrap/cache. access:clear removes both files.
php artisan optimizerunsaccess:cache, andphp artisan optimize:clearrunsaccess:clear.- The cache is used as it is, the way Laravel uses its route and event caches: run it again in every deployment, after adding, moving or deleting a control, or adding a
reindexWhen(). - It runs once every service provider has booted, so it caches the controls of every directory passed to
Access::discoverControlsIn(). - A cached control class that was deleted since is skipped.
access:checkreports a stale cache:stale_control_cachefor the controls,stale_watch_cachefor the watched models. See access:check.
Without the cache, the package discovers the controls when a model first asks for its control. With Laravel Scout installed, the first Eloquent write of a process also builds the control of every discovered ControlledSearchable model, to know which writes reindex which documents: the cache spares that work in production.
The about command
php artisan about prints an "Access Control" section:
php artisan about --only=access_control
Access Control ................................................................
Automatic policies ................................................. registered
Cache .............................................................. not cached
Controls ................................................................... 12
Discovery paths .................................................. app/Access/Controls
Scout ...................................................... installed, meilisearch driver
Version ........................................................................ 1.0.0
laravel-rest-api ............................... installed, AccessControlExtension enabled
| Row | Value |
|---|---|
Version | The installed version of the package. |
Controls | The number of controls, read from the cache when it exists, else from the discovery paths. No control is built. When discovery fails, the row reads discovery failed: and the first line of the error. |
Discovery paths | Every directory the controls are discovered in, relative to the base path: app/Access/Controls first, then the ones added with Access::discoverControlsIn(). |
Cache | cached when access:cache wrote its file, not cached otherwise. |
Automatic policies | registered after Access::registerPolicies(), not registered otherwise, or when the application replaced the policy guesser afterwards. |
Scout | not installed, or the driver of the environment. |
laravel-rest-api | not installed, AccessControlExtension enabled, or AccessControlExtension listed in rest.disabled_extensions. |
--jsongives the same rows under theaccess_controlkey.- The section is registered when the application runs in the console.
- An empty value prints
none, and a row that cannot be read printsunavailable:with the first line of the error: the section never makesaboutfail.
Add this section when you report an issue.