Skip to content

MVC Console

Leaf MVC and Leaf API come with a robust console tool to help you manage your app from the command line. We call this tool Aloe.

Aloe comes with a predefined set of commands which provide project scaffolding, database and app management right from your terminal. To view all available commands, run php leaf list from your terminal.

Aloe CLI vs Leaf CLI

Before we go any further, it's important to note that Aloe is not the same as Leaf CLI.

Leaf CLI is a tool for creating and managing your Leaf applications, it is installed globally and can be used in Leaf and Leaf MVC/Leaf API applications. The Leaf CLI has a more generalized set of commands which can be used in any Leaf application.

Aloe on the other hand is a tool for managing Leaf MVC and Leaf API applications. It is limited to the root directory of your Leaf MVC/Leaf API application and has a more specific set of commands which are only available in Leaf MVC/Leaf API applications.

Aloe Commands

Aloe provides a large set of commands to ease your development process. Although they may look like a lot, we can group them into 6 categories:

  • App commands
  • Scaffold commands
  • Generate commands
  • Delete commands
  • Database commands
  • View commands

App Commands

App commands are commands which help you manage your Leaf MVC/Leaf API application. These commands are used to manage your app's state, interact with your app and it's dependencies and more.

Serve

The serve command is used to start the Leaf development server. It is the same as running php -S localhost:[PORT] from your terminal, but it also runs your app's bootstrapping process.

To start the Leaf development server, run php leaf serve from your terminal. You can also specify a port to run the server on by running php leaf serve --port=[PORT].

php leaf serve

Interact

The interact command is used to start the Leaf interactive shell. The interactive shell is a REPL (Read-Eval-Print-Loop) which allows you to interact with your app from the command line. It is powered by PsySH.

php leaf interact

Up and Down

The app:up and app:down commands are used to put your app in maintenance mode. When your app is in maintenance mode, all requests to your app will return a 503 response. This is useful when you want to take your app down for maintenance.

To put your app in maintenance mode, run php leaf app:down. To take your app out of maintenance mode, run php leaf app:up.

php leaf app:down
php leaf app:up

Scaffold Commands

Scaffold commands are commands which help you scaffold your Leaf MVC/Leaf API application. These commands are used to create new files and folders in your app. Some of these commands even scaffold entire flows for you.

Auth Scaffold

The auth:scaffold command is used to scaffold basic authentication for your Leaf MVC/Leaf API application. It creates required models, controllers, views and routes, migrations and everything you need to get started with authentication. Depending on your flow, you may need to make some changes to the files generated by this command.

Note that this command will generate different files depending on whether you're using Leaf MVC or Leaf API.

If you're building a Leaf MVC app, this command will automatically scaffold a login and registration flow for you with views and controllers, however, since Leaf API comes with the View layer disabled, this command will only scaffold the required models, controllers, routes and migrations for you. All controllers in Leaf API will return JSON responses.

You can force the command to generate files for Leaf MVC or Leaf API by passing the --mvc or --api flag respectively.

php leaf auth:scaffold
php leaf auth:scaffold --mvc # force Leaf MVC
php leaf auth:scaffold --api # force Leaf API

You can find the Leaf MVC authentication documentation here.

Mail Setup

The mail:setup command is used to setup mailing in your Leaf MVC/Leaf API application. It installs the Leaf Mail package and creates a mail.php config file in your config folder as well as a demo mailer in your app/mailers folder.

php leaf mail:setup

Find the MVC Mail documentation here.

Env Generate

The env:generate command is used to generate a .env file in your Leaf MVC/Leaf API application. It generates a .env file from your .env.example file and fills it with the values in your .env.example file.

If there is no .env.example file in your app, this command will generate a .env file from scratch.

php leaf env:generate

Devtools Install

The devtools:install command is used to install and setup the Leaf PHP devtools in your Leaf MVC/Leaf API application.

php leaf devtools:install

You can find the Leaf PHP devtools documentation here.

View Install

The view:install command is used to install and setup the frontend of your Leaf MVC/Leaf API application. It can be used to install any frontend framework of your choice, vite, tailwind or a template engine like bare ui. You can use the --react, --vue, --blade, and --bareui options to scaffold your frontend setup.

php leaf view:install --react

You can also use the --vite and --tailwind options to scaffold Vite and Tailwind respectively.

php leaf view:install --vite
php leaf view:install --tailwind

You can check the frontend documentation for more information.

Generate Commands

These commands are used to generate files like controllers, models, migrations, views and more directly into your app.

Generate Command

The g:command command is used to generate a new console command in your Leaf MVC/Leaf API application. It creates a new command class in your app/commands folder.

php leaf g:command [name]

Generate Controller

The g:controller command is used to generate a new controller in your Leaf MVC/Leaf API application. It creates a new controller class in your app/controllers folder.

php leaf g:controller [name]

This command can also be used to generate a controller with a resource route. To generate a controller with a resource route, pass the --resource flag.

php leaf g:controller [name] --resource

Resource controllers are controllers which have a route for every CRUD operation. You can find more information about resource controllers here.

You can also generate a controller and a model at the same time by passing the --model flag.

php leaf g:controller [name] --model

You can also generate a migration and model at the same time by passing the --all flag, or just -a for short.

php leaf g:controller [name] --all
php leaf g:controller [name] -a

Generate Factory

The g:factory command is used to generate a new model factory in your Leaf MVC/Leaf API application. It creates a new factory class in your app/database/factories folder.

php leaf g:factory [name]

Generate Helper

The g:helper command is used to generate a new helper class in your Leaf MVC/Leaf API application. It creates a new helper class in your app/helpers folder.

php leaf g:helper [name]

Generate Mailer

The g:mailer command is used to generate a new mailer in your Leaf MVC/Leaf API application. It creates a new mailer class in your app/mailers folder.

php leaf g:mailer [name]

Generate Migration

The g:migration command is used to generate a new migration in your Leaf MVC/Leaf API application. It creates a new migration file in your app/database/migrations folder.

php leaf g:migration [name]

By default, this command assumes your table name from the migration name. For example, if you run php leaf g:migration users, the command will assume your table name is users. You can override this by passing the --table flag.

php leaf g:migration [name] --table=[table_name]

Generate Model

The g:model command is used to generate a new model in your Leaf MVC/Leaf API application. It creates a new model class in your app/models folder.

php leaf g:model [name]

If you want to generate a model with a migration, you can pass the --migration flag.

php leaf g:model [name] --migration

Generate Seed

The g:seed command is used to generate a new seed file in your Leaf MVC/Leaf API application. It creates a new seed file in your app/database/seeds folder.

php leaf g:seed [name]

Generate Template

The g:template command is used to generate a new view file in your Leaf MVC/Leaf API application. It creates a new view file in your resources/views folder.

php leaf g:template [name]

You can tell this command what kind of view file you want to create using the --type flag. The available types are blade, jsx, vue and html.

php leaf g:template [name] --type=blade
php leaf g:template [name] --type=jsx
php leaf g:template [name] --type=vue
php leaf g:template [name] --type=html

Delete Commands

These commands are used to delete files like controllers, models, migrations, views and more directly from your app.

Delete Command

The d:command command is used to delete a console command from your Leaf MVC/Leaf API application. It deletes a command class from your app/commands folder and automatically unregisters it from Aloe.

php leaf d:command [name]

Delete Controller

The d:controller command is used to delete a controller from your Leaf MVC/Leaf API application. It deletes a controller class from your app/controllers folder.

php leaf d:controller [name]

Delete Factory

The d:factory command is used to delete a model factory from your Leaf MVC/Leaf API application. It deletes a factory class from your app/database/factories folder.

php leaf d:factory [name]

Delete Migration

The d:migration command is used to delete a migration from your Leaf MVC/Leaf API application. It deletes a migration file from your app/database/migrations folder.

php leaf d:migration [name]

Delete Model

The d:model command is used to delete a model from your Leaf MVC/Leaf API application. It deletes a model class from your app/models folder.

php leaf d:model [name]

Delete Seed

The d:seed command is used to delete a seed file from your Leaf MVC/Leaf API application. It deletes a seed file from your app/database/seeds folder.

php leaf d:seed [name]

Database Commands

These commands are used to manage your database. They are used to create, migrate, seed and rollback your database.

Install Database

The db:install command is used to create a new database from your .env file. It creates a new database using the credentials in your .env file.

php leaf db:install

Migrate Database

The db:migrate command is used to run your database migrations. It runs all migrations in your app/database/migrations folder.

php leaf db:migrate

You can also run a specific migration by passing the migration name to the --file flag.

php leaf db:migrate --file=[migration_name]
php leaf db:migrate --file=users # runs the ..._create_users_table migration

You can also seed your database after running your migrations by passing the --seed flag.

php leaf db:migrate --seed

Reset Database

The db:reset command is used to rollback, migrate and seed your database. It runs the db:rollback, db:migrate and db:seed commands in that order.

php leaf db:reset

If you want to prevent seeding your database, you can pass the --noSeed flag.

php leaf db:reset --noSeed

Rollback Database

The db:rollback command is used to rollback your database migrations. It rolls back all migrations in your app/database/migrations folder.

php leaf db:rollback

You can also rollback a specific migration by passing the migration name to the --file flag.

php leaf db:rollback --file=[migration_name]
php leaf db:rollback --file=users # rolls back the ..._create_users_table migration

You may also rollback a specific number of migrations by passing the number to the --step flag.

php leaf db:rollback --step=[number]
php leaf db:rollback --step=2 # rolls back the last 2 migrations

Seed Database

The db:seed command is used to seed your database. It runs all seed files loading in the app/database/seeds/DatabaseSeeder.php file. In this file, you can specify which seed files to run.

php leaf db:seed

View Commands

These commands are used to manage your frontend. They are used to build, serve and install your frontend. We already covered the view:install command in the Scaffold Commands section above.

Build Frontend

The view:build command is used to build your frontend. It builds your frontend using the build command specified in your package.json file.

php leaf view:build

Serve Frontend

The view:serve command is used to serve your frontend. It serves your frontend using the dev command specified in your package.json file.

php leaf view:serve

Command List

This is a list of every command available in Aloe. To view this list from your terminal, run php leaf list.

Leaf MVC v3.5.0

Usage:
  command [options] [arguments]

Options:
  -h, --help            Display help for the given command. When no command is given display help for the list command
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi|--no-ansi  Force (or disable --no-ansi) ANSI output
  -n, --no-interaction  Do not ask any interactive question
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  completion        Dump the shell completion script
  example           example command's description
  help              Display help for a command
  interact          Interact with your application
  list              List commands
  serve             Start the leaf development server
 app
  app:down          Place app in maintainance mode
  app:up            Remove app from maintainance mode
 auth
  auth:scaffold     Scaffold basic app authentication
 d
  d:command         Delete a console command
  d:controller      Delete a controller
  d:factory         Delete a model factory
  d:migration       Delete a migration
  d:model           Delete a model
  d:seed            Delete a model seeder
 db
  db:install        Create new database from .env variables
  db:migrate        Run the database migrations
  db:reset          Rollback, migrate and seed database
  db:rollback       Rollback all database migrations
  db:seed           Seed the database with records
 devtools
  devtools:install  Install the Leaf PHP devtools
 env
  env:generate      Generate .env file
 g
  g:command         Create a new console command
  g:controller      Create a new controller class
  g:factory         Create a new model factory
  g:helper          Create a new helper class
  g:mailer          Create a new mailer
  g:migration       Create a new migration file
  g:model           Create a new model class
  g:seed            Create a new seed file
  g:template        Create a new view file
 mail
  mail:setup        Install leaf mail and setup mail config
 view
  view:build        Run your frontend dev server
  view:dev          [view:serve] Run your frontend dev server
  view:install      Run a script in your composer.json
MVC Console has loaded