//app/console/Kernel.php
use Illuminate\Support\Facades\Mail; //for use Mail facade
protected function schedule(Schedule $schedule)
{
$forgot = [];
$forgotCheckout = Working::whereNull('deleted_at')->get();
foreach($forgotCheckout as $forgot){
$forgot;
}
if(!is_null($forgot)){
$schedule->call(function () use($forgotCheckout){
Mail::send( //send email with valiable $forgot in View file.
'emails.forgot_checkout',
compact('forgotCheckout'),
function ($message) {
$message->to('test@email.com');
$message->subject('This is test mail');
}
);
})->daily()->when(function() use ($forgotCheckout){ //define how often do this job
if(!is_null($forgot)){
\Log::info(Daily check completed.); //write log file
return true; // when() will work when return is true.
}
else {
return false; // when() not work because return is false.
}
);
}
}
你可以制作和修改你的数据
$forgot
// view/emails/forgot_checkout.blade.php
This is test mail for scheduled mail sending...
@foreach($forgotCheckout as $forgot)
{{$forgot->id}}
{{$forgot->name}}
@endforeach
大多数人都知道,如果你知道怎么做,那就不难了:)