CLI
Getting Started
Zap includes a command line interface (CLI) for generating application files, preparing databases, running migrations, caching routes, and clearing resources. Run commands from the project root with PHP installed and available in your terminal.
The console entry point registers the available commands. List them by running:
php console
php console list
To see command-specific usage and examples, append --help or -h where supported. Commands that accept a name generally show their usage when no name is provided.
Generating Files
Use the make:controller and make:model commands to create classes from the built-in stubs. Controller files are created in app/Controllers, and model files are created in app/Models. Existing files are not overwritten.
php console make:controller UserController
php console make:model User
The model stub derives a table name by lowercasing the model name and adding s. Review and adjust the generated file if your class or database table uses a different naming convention.
Generating an Environment File or Key
The generate command can print a fresh application key or create .env from its stub:
php console generate --key
php console generate --env
Copy the generated key into ZAP_KEY in your environment file. If .env already exists, the environment-file command asks before replacing it.
Creating a Migration File
Migration names determine which stub is selected. Use names like create_users_table, add_email_to_users_table, drop_column_email_from_users, drop_table_users, or change_users_table. Other names use the general update stub.
php console make:migration create_users_table
php console make:migration add_email_to_users_table
php console make:migration drop_table_users
Generated migration files are timestamped and placed in the project-level migrations directory. Open each generated file and define the schema changes in its up() and down() methods as appropriate.
Database
For MySQL, make:database creates a database using the connection settings in config/database.php. You can pass a database name directly. Without one, the command prompts for a name and may offer the configured default.
php console make:database myapp_db
php console make:database
This command creates MySQL databases; it is not used to create an SQLite database. SQLite files are created when the application connects using the configured SQLite path.
Migrations
After configuring the database and adding migration files to migrations, run pending migrations with migrate:start. Zap records completed migrations and assigns them to a batch.
php console migrate:start
php console migrate:status
Use migrate:status to compare the migration files with the recorded migrations. Run migrate:start first to initialize the migration tracking table.
Rollback accepts either --last to undo the most recently recorded migration or --all to process all recorded migrations in reverse order. When a migration has a down() method, it is called before the migration record is removed.
php console migrate:rollback --last
php console migrate:rollback --all
migrate:fresh rolls migrations back, drops the migration tracking table, and runs migrations again. It asks for confirmation, but can remove application data. Back up your database before using it.
php console migrate:fresh
Route Cache
After changing route definitions, use cache:routes to build the route cache from routes/web.php. The cache is written under storage/cache/routes.
php console cache:routes
Clearing Resources
The clear command clears logs by default. Select a resource with a subcommand or its short/long option. The all subcommand clears logs, session files, and cache; views clears compiled views.
php console clear
php console clear logs
php console clear sessions
php console clear cache
php console clear views
php console clear all
The available flags are -l/--log, -s/--session, -c/--cache, -v/--views, and -a/--all. To clear a custom directory, provide its path after dir:
php console clear -v
php console clear dir storage/tmp
Clearing a custom directory removes its contents recursively. Check the target path carefully before running that command.