Wei*_*Wei 5 php scheduled-tasks task-queue laravel laravel-5.6
我正在尝试安排一封电子邮件来提醒明天必须完成的任务的用户。我做了一个自定义命令email:reminder
。这是我在自定义命令中的代码:
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Todo;
use Illuminate\Support\Facades\Mail;
class SendReminderEmail extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'email:reminder';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Remind users of items due to complete next day';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
//
/*
* Send mail dynamically
*/
/*
* hardcoded email
*/
Mail::queue('emails.reminder', [], function ($mail) {
$mail->to('example@email.com')
->from('todoreminder@gmail.com', 'To-do Reminder')
->subject('Due tomorrow on your To-do list!');
}
);
$this->info('Reminder email sent successfully!');
}
}
Run Code Online (Sandbox Code Playgroud)
我现在对电子邮件进行了硬编码以对其进行测试,但是当我运行时php artisan email:reminder
,我得到了一个例外
[InvalidArgumentException]
Only mailables may be queued.
Run Code Online (Sandbox Code Playgroud)
然后我检查了 Laravel 的文档,但任务调度和电子邮件队列是 2 个独立的主题。
任何帮助是极大的赞赏!
使用控制台内核来调度排队作业很容易做到。Laravel 提供了多种包装方法,使 cron 集成变得简单。这是一个基本示例:
$schedule->job(new SendTodoReminders())->dailyAt('9:00');
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8454 次 |
最近记录: |