请帮助我,我正在尝试在服务器上执行cron作业,以向用户发送电子邮件 我创建了这样的命令:
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'contract:end';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Send an email to user about the end of a contract';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$contracts = Contract::where('end_date', Carbon::parse(today())->toDateString())->get();
foreach ($contracts as $contract) {
Mail::to(Setting::first()->value('email'))->send(new ContractEmail($contract));
}
}
在我的kernel.php
中添加了以下代码:
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
//
Commands\ContractEnd::class,
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('contract:end')
->everyMinute();
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
在我的服务器上,我运行以下命令来运行cron作业:
cd /archive/artisan && schedule:run >> /dev/null 2>&1
但是它没有发送任何电子邮件,因为这是我第一次使用它,所以有人可以帮助我吗?
答案 0 :(得分:0)
由于服务器中的命令错误,因此您需要指定正确的路径,该路径将包含/ home /您的用户名/您的网站文件夹/工匠,例如
/usr/local/bin/php /home/your user name which you can get in from job page/archive/artisan schedule:run 1>> /dev/null 2>&1