我正在使用Laravel 5.0。*,现在我想在我的应用程序中实现cron作业。 我搜索了很多,但我什么都没得到,所有示例和视频教程都与5.1和5.3相关,即使我在laravel.com中搜索5.0版本下的任务调度,但它什么都没有显示
参考视频链接:video link
使用上面的视频参考后,我在终端中收到以下错误。
[2016-11-02 08:47:06] local.ERROR:异常'InvalidArgumentException',消息'在“cron”命名空间中没有定义命令。在D:\ harendar \ htdocs \ nkbuild \ vendor \ symfony \ console \ Symfony \ Component \ Console \ Application.php:501
/app/Console/Kernel.php
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel {
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
'App\Console\Commands\Inspire',
'App\Console\Commands\LogDemo',
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('inspire')
->hourly();
$schedule->command('log:demo')->emailOutputTo('harendar@solutionavenues.com');
}
}
/app/Console/Commands/LogDemo.php
<?php namespace App\Console\Commands;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class LogDemo extends Command {
/**
* The console command name.
*
* @var string
*/
protected $name = 'log:demo';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Log Demo command.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
\log::info('I was here @ ', \Carbon\Carbon::now());
}
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return [
['example', InputArgument::REQUIRED, 'An example argument.'],
];
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return [
['example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null],
];
}
}
答案 0 :(得分:0)
Hello首先你需要运行命令:php artisan make:console test(命令名)。
然后你会发现在app / Console / Commands / test.php下创建了一个test.php命令。这看起来像是:
命名空间App \ Console \ Commands;
使用Illuminate \ Console \ Command;
class test extends Command { / ** *控制台命令的名称和签名。 * * @var字符串 * / protected $ signature =&#39; test&#39;;
/**
* 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 handle()
{
//
}
}