laravel command
(1) 新建一个command类,并在command类里面写相应的执行函数
其中变量act就是指函数名,handle里面会先判断该函数是不是存在,如果存在就执行,如果不存在就提示函数不存在
class UploadTeachingMaterials extends Command
{
protected $signature = 'uploadMaterials {act} {--folder=}';
protected $description = '上传教材'; /**
* 执行控制台命令
*/
public function handle()
{
$method = $this->argument('act');
if (method_exists($this, $method)) {
$this->$method();
echo "执行完成\n";
} else {
echo "${method} is not exists\n";
}
}
public function test()
{
xxxxxxx;
}
}
应先填写类的 signature 和 description 属性,这会在使用 list 命令的时候显示出来。执行命令时会调用 handle 方法,你可以在这个方法中放置命令逻辑。
到相应的目录下:比如你的laravel项目名叫test,那你就应该在test/目录下执行
php artisan list

(2)在kernel.php中注册该类
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [ Commands\TeachingMaterials\UploadTeachingMaterials::class, ]; /**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{ }
}
(3)执行该command命令
php artisan uploadMaterials 方法名 --folder=变量名
注意:
在执行command的命令的时候,为了对用户更友好,要有输出结果和提示,同时要进行错误处理,将异常和错误,或者其他有用的信息放到日志中。
laravel command的更多相关文章
- union: php/laravel command
#########Laravel###############2018-01-09 16:46:26 # switch to maintenance mode php artisan down # s ...
- laravel command命令行
生成类 为了创建一个新命令,你可以使用Artisan中的 command:make 命令生成一个骨架作为你的起点: 生成一个命令类 php artisan command:make FooComman ...
- Mac laravel: command not found
如果用的oh-my-zsh 安装laravel 提示找不到.可以试试下面的 export PATH=$HOME/bin:/usr/local/bin:~/.composer/vendor/bin:$P ...
- laravel command调用方法命令
- Laravel Quickstart
Installation Via Laravel Installer First, download the Laravel installer using Composer. composer gl ...
- Laravel 安装记录
系统环境:ubuntu-14.10-server-i386(32) LAMP 系统默认安装 根据:http://laravel.com/docs/5.1 官方文档,准备通过 Composer 安装 ...
- mac系统下安装Composer和laravel
先手动下载Composer 地址:https://getcomposer.org/composer.phar 下载后mv composer.phar /usr/local/bin/composer 这 ...
- Laravel + Swoole 打造IM简易聊天室
最近在学习Swoole,利用Swoole扩展让PHP生动了不少,本篇就来Swoole开发一款简易的IM聊天室 应用场景:实现简单的即时消息聊天室. (一)扩展安装 pecl install swool ...
- Task Scheduling
Introduction In the past, developers have generated a Cron entry for each task they need to schedule ...
随机推荐
- svn导出文件夹到另外目录export
svn导出文件夹到另外目录export 2.选择目录,下面两个选项不用勾选 3.有存在的文件选择overwrite覆盖,勾选下面的同样操作
- 代码静态扫描工具sonar
一.SonarQube整体介绍 SonarQube为静态代码检查工具,采用B/S架构,帮助检查代码缺陷,改善代码质量,提高开发速度,通过插件形式,可以支持Java.C.C++.JavaScripe等等 ...
- python网络编程之一
套接字的详细介绍会在另一篇博文指出,此片博文主要是python套接字的简单客户端编写. 两种套接字介绍: 面向连接的套接字:面向连接的套接字提供序列化,可靠的和不重复的数据交付.面向连接是可靠的传输, ...
- 关于STM32 MDK中USE_STDPERIPH_DRIVER问题的解释
初学STM32,在RealView MDK 环境中使用STM32固件库建立工程时,初学者可能会遇到编译不通过的问题.出现如下警告或错误提示: warning: #223-D: function &qu ...
- VC++实现获取文件占用空间大小的两种方法(非文件大小)
// GetFileSpaceSize.cpp : Defines the entry point for the console application. // /***************** ...
- CF873B Balanced Substring
1到n内0,1个数相同的个数的最长字串 \(i>=j\) \[1的个数=0的个数\] \[sum[i]-sum[j-1]=i-(j-1) - (sum[i]-sum[j-1])\] 这里把\(( ...
- Spring Boot详细学习地址转载
阿里中间件牛人,学习榜样,源码分析: https://fangjian0423.github.io/ 基础.详细.全面的教程: https://gitee.com/roncoocom/spring-b ...
- 《EMCAScript6入门》读书笔记——16.Generator函数的语法
鼠标指针移到图片上,右键,选择在“在新标签页中打开”,放大即可看到清晰文字.
- 新增html5标签 例如input的很多属性
<meter> 标签定义度量衡.仅用于已知最大和最小值的度量. contenteditable="true"> 规定可编辑的内容. <output> ...
- [不屈的复习] - http://how2j.cn/
http://how2j.cn/ 该教程网站分得比较规整!