The spark console tool
spark is a console program that sits in the project root. It starts the development server, creates class skeletons and changes the database structure. Writing those files by hand is allowed, but the command puts them in the right folder and never mistypes a name.
How to run it
Commands are run in a terminal from the project folder — the one that contains the spark file:
php sparkWithout arguments the program prints the framework version and the list of all commands, split into groups.
The development server
php spark serveThe site opens at http://localhost:8080. The server works while the terminal is open; stop it with Ctrl+C. If the port is busy, choose another one:
php spark serve --port 8081Now the site address is http://localhost:8081.
Help for a command
php spark help serveThe help command prints the description of any other command and the list of its options.
Creating files
Commands that start with make: create a class skeleton:
php spark make:controller PostsThe file Posts.php appears in the app/Controllers folder, and the terminal prints its path.
| Command | What it creates | Where |
|---|---|---|
make:controller Posts | A controller | app/Controllers |
make:model PostModel | A model | app/Models |
make:migration CreatePosts | A migration | app/Database/Migrations |
make:seeder PostSeeder | A seeder | app/Database/Seeds |
make:filter AuthFilter | A filter | app/Filters |
make:command SendReport | Your own command | app/Commands |
What each of these words means is explained in the following lessons.
Useful commands
| Command | What it does |
|---|---|
php spark routes | Shows every address of the site |
php spark env | Shows the current environment |
php spark migrate | Updates the database structure |
php spark db:seed PostSeeder | Fills the database with data |
php spark cache:clear | Clears the cache |
Common mistake
The php spark command works only from the project root. Run it from the app or public folder and the terminal answers that the spark file cannot be found. Before running, check that you are in the blog folder: app, public and spark must be visible there.