I have some command line scripts that I would like to modify to use Laravel's features (Eloquent etc).

How do I do that? I am aware that Laravel bootstraps from the index.html file. Is there any provision for running command-line apps / scripts?

 

  1. php artisan make:command MyCommand.
  2. Go to /app/Console/Commands/MyCommand.php
  3. Find:

    protected $signature = 'command:name';
  4. Change to:

    protected $signature = 'my:command';
  5. There's handle() method there you are able to fire some code:

    public function handle()
    {
        echo 'Hello world';
    }
  6. In the /app/Console/Kernel.php you will find protected variable $commands. Add your Command's class name.

    protected $commands = [
        // ...
        Commands\MyCommand::class,
    ];
  7. Run php artisan my:command.

原文引用自 https://stackoverflow.com/questions/40993513/command-line-scripts-in-laravel


文章標籤
創作者介紹
創作者 Frank 的頭像
Frank

經驗交流分享與備忘

Frank 發表在 痞客邦 留言(0) 人氣()