# Commands
Tea comes with pre-installed commands, however you can create your own commands as well.
# Available commands
By running php tea
you can view all the available commands.
******************************************************************************************************************
Available commands
down Bring down the application
key:generate Generate secret key
make:collection Create a collection
make:command Create a Tea command
make:controller Create a controller
make:middleware Create a middleware
make:migration Create a migration
make:model Create a model
make:observer Create an observer
make:request Create a request
make:resource Create a resource
make:rule Create a rule
migrate:refresh Reset and re-run all migrations
run Run the application
up Bring up the application
******************************************************************************************************************
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
down, key:generate, make:collection, make:command, make:controller, make:middleware, make:migration, make:model, make:observer, make:request, make:resource, make:rule, migrate:refresh, run, up
# down
php tea down
Bring down the application.
# key:generate
php tea key:generate
Generate secret key.
NO NEED TO RUN THIS COMMAND YOURSELF! THIS COMMAND IS EXECUTED AUTOMATICALLY AFTER THE PROJECT IS INSTALLED.
# make:collection
php tea make:collection name=CollectionName resource=ResourceName
Create a collection.
# make:command
php tea make:command name=CommandName
Create a Tea command.
# make:controller
php tea make:controller name=ControllerName
Create a controller.
# make:middleware
php tea make:middleware name=MiddlewareName
Create a middleware.
# make:migration
php tea make:migration name=CreateNameTable table=table_name
Create a migration.
# make:model
php tea make:model name=ModelName
Create a model.
# make:observer
php tea make:observer name=ObserverName model=ModelName
Create an observer.
# make:request
php tea make:request name=RequestName
Create a request.
# make:resource
php tea make:resource name=ResourceName
Create a resource.
# make:rule
php tea make:rule name=RuleName
Create a rule.
# migrate:refresh
php tea migrate:refresh
Reset and re-run all migrations.
# run
php tea run
Run the application.
# up
php tea up
Bring up the application.
# Create a command
To create a new command, run:
php tea make:command name=SayHiCommand
<?php
namespace App\Console;
use Devlob\Commands\Command;
class SayHiCommand extends Command
{
protected $params = [];
protected $description = 'Command description';
public function handle(object $args)
{
//
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$description is the description that will be displayed when running php tea
$params is an array where you define the parameters of the command.
handle is where you do all your work.
Suppose the command above accepts a name argument and prints a hi message, then it will look like this:
<?php
namespace App\Console;
use Devlob\Commands\Command;
class SayHiCommand extends Command
{
protected $params = ['name'];
protected $description = 'Say hi';
public function handle(object $args)
{
$this->console->green("Hi $args->name");
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Register commands
Before running the command, let's register it inside app/Console/Kernel.php.
<?php
namespace App\Console;
use Devlob\Commands\ConsoleKernel;
class Kernel extends ConsoleKernel
{
protected $commands = [
'hi' => SayHiCommand::class,
];
}
2
3
4
5
6
7
8
9
10
11
12
hi is the way we will call the command, thus, to run the above command, we run:
php tea hi name=Renato
You should see Hi Renato in your terminal.
# Optional parameters
If a parameter is optional then simply include a ? at the end:
protected $params = ['name?'];
We can run php tea hi
, without passing a name.
You should see Hi in your terminal.
# Utilities
Commands have access to a utility class, currently you can change the color of the text to green, yellow, and red.
public function handle(object $args)
{
$this->console->green("Hi $args->name");
}
2
3
4
The code above will echo Hi Renato in green color.