我想获取表的所有时间戳,将所有内容与当前日期进行比较,并将所有小于当前日期的时间戳进行比较,将一天添加到其各自的时间戳中,这样始终将日期更新为当前日期否则,如果最终日期将过去,它将在明天确定。
命令:
<?php
namespace App\Console\Commands;
use App\pamatrixinf;
use App\Periodicity;
use App\Mail\SendMailable;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Mail;
use Carbon\Carbon;
class Cleanminute extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'E:LD';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Every minute';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$datedi = Periodicity::select('pamatrixinf.dateen')
->where('pamatrixinf.cod_paperiodicity', '=', 1)
->get();
$now = Carbon::now();
if ($datedi<$now) {
pamatrixinf::where('read_at', 1)
->where('cod_paperiodicity', 1)
->update(['read_at' => 0]);
pamatrixinf::where('dateen','<', $now)
->update(['dateen' => 'dateen'->addDay()]);
}
}
}
您可以在我的表中看到,我有read_at字段来知道它是否被看到(用于另一个功能),以及dateen用来告诉我每项工作的截止日期,并且我想与之比较$ now变量, 我希望你能帮帮我。由于我运行命令没有任何错误,但没有任何反应。让我或多或少地让他们知道我想发生什么。
我仍然不执行命令:
id dateen
1 2020-06-03 14:00:00.000000
2 2020-07-05 14:00:00.000000
3 2020-06-07 14:00:00.000000
我执行命令:
id dateen
1 2020-06-04 14:00:00.000000
2 2020-07-05 14:00:00.000000
3 2020-06-08 14:00:00.000000
感谢您的帮助
由于您使用的是get(),因此返回值是一个集合,因此您需要使用foreach循环遍历该集合,如果表中只有一条记录,则可以使用first(),而不再需要使用foreach循环:
示例:
public function handle()
{
$dates = Periodicity::select('pamatrixinf.dateen')
->where('pamatrixinf.cod_paperiodicity', '=', 1)
->get();
$now = Carbon::now();
foreach($dateas as $datedi){
if ($datedi<$now) {
pamatrixinf::where('read_at', 1)
->where('cod_paperiodicity', 1)
->update(['read_at' => 0]);
pamatrixinf::where('dateen','<', $now)
->update(['dateen' => 'dateen'->addDay()]);
}
}
}