0

I need to set some cron jobs on a Laravel website. It seems that first I have to run the following command in the shell to begin with it:

php artisan command:make CustomCommand

However since I don't have shell access, my only other option is to use Artisan::call and access is it over HTTP. The syntax is something like this:

\Artisan::call( 'command:make', 
    array(
        'arg-name' => 'CustomCommand',
        '--option' => ''
    )
);

The problem that I'm facing is that I can't seem to find the arg-name value for the command:make command.

I really appreciate if someone mention the Argument Name for the make command or suggest an alternative solution that doesn't need shell access.

4

1 回答 1

2

您可以通过创建一个代表您的命令的类来手动添加它。cli 命令生成下一个文件:

    <?php

use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

class Test extends Command {

    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = 'command:name';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description.';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function fire()
    {
        //
    }

    /**
     * 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),
        );
    }

}

把它放在你的commands目录中(对于 L4 它是app/commands)。接下来只需将app/start/artisan.php自定义命令的绑定添加到您的文件中:

Artisan::add(new Test); 就是这样。当您不需要触摸服务器的 crontab 时,这是理想的解决方案。如果您可以从 CP 访问它,这将是最简单的解决方案。如果您没有这种能力,现在可以设置 crontab 来运行您的自定义命令。希望这可以帮助。

于 2015-01-09T13:46:30.827 回答