• 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 "执行完成
    ";
            } else {
                echo "${method} is not exists
    ";
            }
        }
      
      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 = [
           
            CommandsTeachingMaterialsUploadTeachingMaterials::class,
    
        ];
    
        /**
         * Define the application's command schedule.
         *
         * @param  IlluminateConsoleSchedulingSchedule  $schedule
         * @return void
         */
        protected function schedule(Schedule $schedule)
        {
    
        }
    }
    复制代码

    (3)执行该command命令

    php artisan uploadMaterials 方法名 --folder=变量名

    注意:

    在执行command的命令的时候,为了对用户更友好,要有输出结果和提示,同时要进行错误处理,将异常和错误,或者其他有用的信息放到日志中。

    转载:https://www.cnblogs.com/cjjjj/p/9754962.html

  • 相关阅读:
    Entity Framework 学习初级篇7基本操作:增加、更新、删除、事务
    Flash Lite基础知识
    instantclient_10_2客户端配置
    Flash Player9.0 跟Flash Player8.0区别
    Adobe Flash Lite3
    flashlite3无法接入网络的解决办法
    sendAndLoad(LoadVars.sendAndLoad 方法)
    乐高模式
    FMS应用实例 从FMS服务器读取文件(图片/SWF/文本)到客户端
    as2.0 fscommand的用法
  • 原文地址:https://www.cnblogs.com/ithubb/p/13859239.html
Copyright © 2020-2023  润新知