生成类

为了创建一个新命令,你可以使用Artisan中的 command:make 命令生成一个骨架作为你的起点:

生成一个命令类

php artisan command:make FooCommand

默认情况下,生成的类文件被存放在 app/commands 目录下,同时你也可以指定自定义目录和命名空间:

php artisan command:make FooCommand --path=app/classes --namespace=Classes

注册命令

一旦你的命令完成后,你需要使用 Artisan 进行注册,这样才能够被使用。这通常在 app/start/artisan.php文件中完成。在这个文件中,你可以使用 Artisan::add 函数注册命令:

注册一个 Artisan 命令

Artisan::add(new CustomCommand);

如果你的命令在应用程序的 IoC 容器 中注册,你可以使用 Artisan::resolve 函数使它对 Artisan 可用:

注册一个在 IoC 容器中的命令

Artisan::resolve('binding.name');

一个发邮件样例:
<?php

use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument; class SendMailCommand extends Command { /**
* The console command name.
*
* @var string
*/
protected $name = 'SendMailCommand:sendMail';//命令名,命令行调用使用php artisian 这里的$name值 /**
* The console command description.
*
* @var string
*/
protected $description = 'send mail.'; /**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
} /**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
//
$command=" C:/sendEmail -f from.sina.com -t to@qq.com -s smtp.sina.com -xu username -xp pasword -u test ";
$message=$this->argument('message');
$str="$command -m $message ";
$this->info($str);
system($str);
$this->info("It's Done, have a good day."); } /**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return array(
array('message', 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),
);
} }

运行:

php artisan  commanname argx --option=bar --option=baz

参考:

http://www.golaravel.com/docs/4.0/commands/

https://phphub.org/topics/34

http://www.sitepoint.com/create-laravel-css-minify-command/

laravel command命令行的更多相关文章

  1. 1)实际时间(real time): 从command命令行开始执行到运行终止的消逝时间; 2)用户CPU时间(user CPU time): 命令执行完成花费的用户CPU时间,即命令在用户态中执行时间总和; 3)系统CPU时间(system CPU time): 命令执行完成花费的系统CPU时

    1)实际时间(real time): 从command命令行开始执行到运行终止的消逝时间: 2)用户CPU时间(user CPU time): 命令执行完成花费的用户CPU时间,即命令在用户态中执行时 ...

  2. Laravel常用命令行中文版

    1.生成控制器 php artisan make:controller ArticleController 对应的会在app/http/controllers下面生成ArticleController ...

  3. windows下安装python、环境设置、多python版本的切换、pyserial与多版本python安装、windows命令行下切换目录

    1.windows下安装python 官网下载安装即可 2.安装后的环境设置 我的电脑--属性--高级--设置path的地方添加python安装目录,如C:\Python27;C:\Python33 ...

  4. java命令行导出、导入sql文件

    @IocBean public class SqlCommandModel{ //用户名 @Inject("java:$conf.get('jdbc.username')") pr ...

  5. Mac系统终端命令行不执行命令 总出现command not found解决方法

    配置过安卓开发环境,改过bash_profile这个文件,最后不知怎么的只有cd命令能执行,我猜测可能修改bash_profile文件后没有保存 导致的     保存命令是:  source .bas ...

  6. Qt_Window@Qt Command Prompt从命令行创建工程

    #include <QApplication> #include <QLabel> int main(int argc, char *argv[]) { QApplicatio ...

  7. MAC 命令行工具(Command Line Tools)安装

    不过升级后安装命令行工具(Command Line Tools)时发现官网没有clt的下载安装包了,原来改了,使用命令在线安装. 打开终端,输入命令:xcode-select --install 选择 ...

  8. mac下使用命令行打包出现bash gradle command not found的解决方案

    命令行打包的时候出现 bash gradle command not found这个问题,主要是因为gradle环境丢失.需要重新配置gradle的环境变量. 1. gradle路径的查找 然后gra ...

  9. Windows命令行command的Shell命令详细解析和语法

    CMD命令大全及详细解释和语法 Microsoft Windows XP [版本 5.1.2600] 有关某个命令的详细信息,请键入 HELP 命令名 ASSOC    显示或修改文件扩展名关联. A ...

随机推荐

  1. Generating SSH Keys on windows

    two ways here I provide: use openSSH command line on git bash(such as msysgit bash) ls -al ~/.ssh ss ...

  2. flutter table 在showModalBottomSheet中

    问题是,不知道为什么又可以了.原来是显示黑屏,没有输出. showModalBottomSheet<void>( context: context, builder: (BuildCont ...

  3. 用阿里云搭建Http代理服务器

    先说下我的运行环境: Ubuntu16.04+python3.5,用的是阿里云ECS乞丐版. 搭建步骤: [python] view plain copy 0. 直接用xshell或putty远程到云 ...

  4. thinkphp5 No input file specified.

    .htaccess文件中的 RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] 在默认情况下会导致No input file specified. 修改成 Rewri ...

  5. 修改linux系统的时间EDT为CST

    今早看到一台机器时间对不上,本以为系统时间与网络北京时间不同步,就在终端命令执行网络时间同步 [root@localhost ~]# ntpdate time.windows.com 执行完之后,在执 ...

  6. java需要掌握内容、核心不断更新中

    1.你需要精通面向对象分析与设计(OOA/OOD).涉及模式(GOF,J2EEDP)以及综合模式.你应该十分了解UML,尤其是class,object,interaction以及statediagra ...

  7. android 开发积累

    1.ListView滚动黑屏问题 ListView滚动时,数据项变成黑色 问题解决办法:通过添加 android:cacheColorHint = "#00000000" 将背景设 ...

  8. Java实现验证码的制作

    验证码概述 为什么使用验证码? 验证码(CAPTCHA)是一种全自动程序.主要是为了区分“进行操作的是不是人”.如果没有验证码机制,将会导致以下的问题: 对特定网站不断进行登录,破解密码: 对某个网站 ...

  9. Windows下通过Composer安装Yii2

    安装好大于5.4或更高版本的PHP环境并开启openssl扩展.如果是Apache服务器,加载Apache的mod_ssl模块. 下载Composer并安装. 开始->运行[或者WIN+R]-& ...

  10. 《C++程序设计》朝花夕拾

      (以后再也不用破Markdown写东西了,直到它有一个统一的标准,不然太乱了--) 函数签名 int f (int a, int b) ↑ ↑ ↑ ↑ 返回类型 函数名 形 式 参 数 其中,函数 ...