php - 使用发送邮件安排通话并登录 Laravel
问题描述
如果某些用户的“deleted_at”字段在日常检查时为“null”,如何制作通知消息?发生这种情况时,我希望向管理员发送一封带有该用户名的电子邮件。
// app/console/Kernel.php
protected function schedule(Schedule $schedule)
{
$schedule->call(function () {
$forgotCheckout = DB::table('workings')->whereNull('deleted_at')->get();
foreach($forgotCheckout as $f){
$user_id = [$f->user_id];
}
-- "code" --
})->daily();
}
解决方案
//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
大多数人都知道,如果您知道该怎么做,那就不难了:)
推荐阅读
- linux - 通过 cron 文件从 FTP 服务器访问和传输文件到我的 ftp 服务器
- android - 从资产文件夹打开后,Android PDF 立即关闭 - 意图
- github - 对 github repo 的流量有些困惑?
- javascript - 如何使用 async/await 从 sqlite db.each 获取数据
- hugo - Hugo 错过了生成图像和其他一些文件夹
- bytecode - 关于如何正确有效地使用 ByteBuddy 的指南
- flutter - 更改选项卡时如何更改 TextField 中的键盘类型?
- flutter - 在构造函数中使用方法来初始化参数?
- jar - 如何在 jmeter 的 beashell 中运行 Java 代码并在 Jmeter 脚本中传递变量
- curl - 使用 GeoLite2 时,浏览器和 curl 或 wget 的不同行为