php - Laravel 使用方法 when() 安排作业
问题描述
以下代码中的错误在哪里?在终端中发出php artisan schedule:run
命令时出现致命错误。
protected function schedule(Schedule $schedule)
{
$schedule->call(function () {
$forgotCheckout = Working::whereNull('deleted_at')->get();
$forgot = [];
foreach($forgotCheckout as $forgot){
$forgot;
}
Mail::send(
'emails.forgot_checkout',
compact('forgot'),
function ($message) use ($forgot) {
$message->to('test@email.com');
$message->subject('This is test mail');
}
);
})->daily()->when(function ($forgot){
if(is_null($forgot)){
return false;
}
else{
return true;
}
});
}
Symfony\Component\Debug\Exception\FatalThrowableError :类型错误:函数 App\Console\Kernel::App\Console{closure}() 的参数太少,通过了 0,预期正好 1
at C:\www\test\app\Console\Kernel.php:50
46| $message->subject('This is test mail');
47|
48| }
49| );
> 50| })->everyMinute()->when(function ($forgot){
51| if(is_null($forgot)){
52| return false;
53| }
54| else{
解决方案
试试下面的代码。
protected function schedule(Schedule $schedule)
{
$forgot = [];
$schedule->call(function () {
$forgotCheckout = Working::whereNull('deleted_at')->get();
foreach($forgotCheckout as $forgot){
$forgot;
}
Mail::send(
'emails.forgot_checkout',
compact('forgot'),
function ($message) use ($forgot) {
$message->to('test@email.com');
$message->subject('This is test mail');
}
);
})->daily()->when(function() use($forgot) {
if(is_null($forgot)){
return false;
}
else{
return true;
}
});
}
更改的代码行:
->daily()->when(function() use($forgot) {
推荐阅读
- r - 使用计数的命名向量创建重复向量序列
- sharepoint - 有没有办法使用 ARM 模板在逻辑应用程序中自动创建共享点在线连接?
- jenkins - 詹金斯:“等待完成 my_job”
- python-3.x - 使用从 pandas 样式对象到另一个 pandas DataFrame 的颜色编码
- ios - 在呈现 UIPopoverViewController 时,如何使除 sourceView 之外的所有内容变暗?
- uml - Plantuml 文件为 10K 行时,无法生成完整的图像,只能生成一半的图像
- sql - 查询在太长时间后返回结果并且仅返回小数据集的结果。在优化方面需要帮助
- sql - 根据某个关键字获取特定行
- google-chrome - 如何在 Google Chrome 的 APP 模式下禁用右键菜单
- flutter - 打开新页面时如何隐藏bottomNavigationBar