Encodera

Thanks for reading!

Donate to the site — we work hard for you.

Contents

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 spark

Without arguments the program prints the framework version and the list of all commands, split into groups.

The development server

php spark serve

The 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 8081

Now the site address is http://localhost:8081.

Help for a command

php spark help serve

The 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 Posts

The file Posts.php appears in the app/Controllers folder, and the terminal prints its path.

CommandWhat it createsWhere
make:controller PostsA controllerapp/Controllers
make:model PostModelA modelapp/Models
make:migration CreatePostsA migrationapp/Database/Migrations
make:seeder PostSeederA seederapp/Database/Seeds
make:filter AuthFilterA filterapp/Filters
make:command SendReportYour own commandapp/Commands

What each of these words means is explained in the following lessons.

Useful commands

CommandWhat it does
php spark routesShows every address of the site
php spark envShows the current environment
php spark migrateUpdates the database structure
php spark db:seed PostSeederFills the database with data
php spark cache:clearClears 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.

Thanks for reading!

Donate to the site — we work hard for you.