You’re browsing the documentation for v3.x.

  Click here  for earlier leaf mvc versions.

# Aloe CLI

This console uses the php console, so you should have php path defined😉

Note

This is just a mini documentation on Aloe CLI and how it is used in Leaf MVC. For the full documentation, please refer to the aloe cli documentation (opens new window)

Aloe is CLI that comes with leaf MVC and Leaf MVC v2 upwards. Aloe is integrated into the leaf script and provides a number of helpful commands that can assist you while you build your application. To view all available commands, you can use the list command or call leaf.

php leaf list
# or
php leaf
1
2
3

Every command also includes a "help" screen which displays and describes the command's available arguments and options. To view a help screen, precede the name of the command with help:

php leaf help db:migrate
1

# Interact (REPL)

Aloe comes with aloe-interact which is basically powerful REPL powered by PSY Shell (opens new window). Interact allows you to interact with your app, access variables and methods in your Leaf app, run and rollback migrations, perform database operations and so much more. You can access interact on aloe like this:

php leaf interact
1

# Writing Commands

Aside all the commands provided by aloe, you can also create your own commands and run them through the aloe cli. Aloe CLI allows you to directly generate commands to run in the CLI.

# Generating Commands

To create a new command, you may use the g:command aloe command. This command will create a new command class in the default commands directory.

The default directory for commands in leaf MVC and Leaf MVC is App\Console, with skeleton, you're free to decide where to place your commands.

php leaf g:command SendMail
1

Aloe can also generate namespaced commands directly for you. You don't have to manually set namespaces as done with other CLI tools.

php leaf g:command mail:send
1

If you want to, you can even generate the command by it's name instead of it's class. Aloe is smart enough to differentiate them.

php leaf g:command shutdown 
1

# Command Structure

After generating your command, you should start writing what to execute once the command is called. Aloe smartly generates a command name for you, even if you create the command using the class name, however, if it doesn't match what you need, you can always change it.

With the mail:send example above, Aloe wil generate App\Console\MailSendCommand, in this file, we'll have something that looks like this:

<?php
namespace App\Console;

use Aloe\Command;

class ExampleCommand extends Command
{
    protected $command = "mail:send";
    protected $description = "mail:send command's description";
    protected $help = "mail:send command's help";

    public function handle()
    {
        $this->comment("mail:send command's output");
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

We can add an argument to find the user to send the email to, and output a message while sending the email.

public function config()
{
    $this->setArgument("user", "required");
}

public function handle()
{
    $user = $this->argument('user');

    $this->comment("Sending email to $user");

    $success = CustomEmailHandler::send($user);

    if ($success) {
        $this->info("Email sent successfully");
    } else {
        $this->error("Couldn't send email, pls try again");
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

# IO

Stuff about input and output

# Registering Commands

By default, aloe cli registers all commands generated, however, if you have a command you want to register manually, or commands from a package which need to use Aloe, you can also add them pretty easily.

Simply locate the aloe file in the root directory of your project, open it up and find a commented section talking about custom commands.

/*
|--------------------------------------------------------------------------
| Add custom command
|--------------------------------------------------------------------------
|
| If you have a new command to add to Leaf
|
*/
$aloe->register(\App\Console\ExampleCommand::class);
1
2
3
4
5
6
7
8
9

An example command has already been registered, so you can follow this example. Simply call the register method. You can also pass in an array of commands to register, as such, a custom package with a couple of commands to register can simply return an array of all those commands.

$aloe->register([
    \App\Console\AppCommand::class,
    CustomPackage::commands(),
]);
1
2
3
4

# Commands

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
 aloe
  aloe:config    Install aloe config
 app
  app:down       Place app in maintainance mode
  app:up         Remove app from maintainance mode
 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
 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: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
 scaffold
  scaffold:auth  Scaffold basic app authentication
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

For the full documentation, you can refer to aloe-cli docs (opens new window)