我有一份工作可以在用戶在應用程序中註冊時發送電子郵件。如何爲隊列創建作業:工作
SendWelcomeEmail.php
<?php
namespace App\Jobs;
use App\Jobs\Job;
use App\User;
use Illuminate\Contracts\Mail\Mailer;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class SendWelcomeEmail extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
protected $user;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(User $user)
{
$this->user = $user;
}
/**
* Execute the job.
*
* @return void
*/
public function handle(Mailer $mailer)
{
$user = &$this->user;
$message = sprintf('Hello %s', $user->name);
$mailer->raw($message, function ($m) use ($user){
$m->from('[email protected]', 'Lucas Lopes');
$m->to($user->email, $user->name);
});
}
}
我想創建一個作業執行PHP工匠隊列:每分鐘發送隊列中的電子郵件的工作命令。
不需要在設置命令'app/Console/Kernel.php'多久執行一次? –