CLI: the playground
php artisan expression:playground
Opens an interactive REPL against a live Engine and a context you build
up as you go — the fastest way to check what an expression does before
storing it.
$ php artisan expression:playground
expr › /fake
Fake context generated under "trigger". Try: trigger.items.filter(current.active).map(current.name)
expr › trigger.items.filter(current.active).map(current.name)
=> ["voluptatibus tenetur","placeat odio","eum et"] (array, 3.12ms)
chainable: all, any, avg, chunk, contains, count, diff …+30 more
expr › trigger.name.upper(
ParserException: Unexpected token '' at position 19.
trigger.name.upper(
^
Type an expression to evaluate it. A line containing {{ and }} is
treated as a template and run through resolve(); anything else is run
through evaluate(). Each result shows its type and timing, and — for
non-template results — a preview of what can be chained next. Parse and
lex errors point a caret at the offending character.
Options
| Option | Effect |
|---|---|
--strict | Start the engine in strict mode |
--context=<file> | Preload a JSON file as the starting context |
php artisan expression:playground --strict --context=storage/sample-trigger.json
Commands
| Command | Description |
|---|---|
/help | List all commands |
/block | Enter multi-line code-block mode (run()); a blank line executes |
/context, /ctx | Print the current context as JSON |
/set <path> <value> | Set a context value — value may be JSON (/set trigger.tags ["a","b"]) or a bare word |
/clear | Reset the context to empty |
/import <file> | Merge a JSON file into the context |
/export <file> | Write the current context to a JSON file |
/factory <Model::class> [count] | Generate context from an Eloquent factory — uses ->make(), never touches the database |
/fake | Populate trigger with built-in demo data (requires fakerphp/faker) |
/methods [type] | List chainable methods, optionally filtered by type |
/functions | List available functions |
/suggest <expr> | Evaluate <expr> and show its type and chainable methods |
/keys <expr> | Evaluate <expr> (a list) and show the union of its item keys |
/strict | Toggle strict mode |
/history | Show the expressions run this session |
/exit, /quit | Leave |
/fake requires fakerphp/faker:
composer require fakerphp/faker --dev
Without it, use /factory with your own models, /set, or /import
instead.
Notes
- The engine is built from your published
config/expression-engine.php, with--strict//strictlayered on top. /factoryneeds an Eloquent model with an associated factory; the generated records are never persisted.- Arrow-key history and line editing are available when PHP's
readlineextension is present.