1、php artisan command:make TestCommand
执行完后,会在 app/commands 文件夹中生成 TopicMakeExcerptCommand.php 文件
2、注册命令
在 app/start/artisan.php 文件里面, 添加以下
Artisan::add(new TestCommand);
<?php
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class TestCommand extends Command {
/**
* The console command name.
*
* @var string
*/
protected $name = 'test';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command test.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
$res = DB::table('person')->get();
print_r($res);
}
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return array(
// array('example', InputArgument::REQUIRED, 'An example argument.'),
);
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return array(
// array('example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null),
);
}
}