Lov*_*ock 5 php sql laravel eloquent laravel-5
我有一系列的日子想要检查以 Laravel Spark 结束的试验:
$trialIntervals = [10, 5, 3, 1, 0];
Run Code Online (Sandbox Code Playgroud)
我获取所有团队,然后使用 diffInDays 检查他们的 Trial_ends_at 日期是否为间隔之一:
$daysTillTrialEnds = Carbon::parse($team->trial_ends_at)->diffInDays(Carbon::now());
Run Code Online (Sandbox Code Playgroud)
然后,我检查该值是否已经是数据库和间隔中的现有结果:
if ( in_array($daysTillTrialEnds, $trialIntervals) && !TrialEndingNotification::where('team_id', $team->id)->where('days_notified_at', $daysTillTrialEnds)->count() ) {
// not yet been added to db
}
Run Code Online (Sandbox Code Playgroud)
我有一个名为“days_notified_at”的字段,我正在使用该字段检查我是否已添加该行并通知客户。然而,该字段再也不会使用,我宁愿引用created_at日期并删除该字段。
我的问题是我基本上是如何做到这一点的:
->where(Carbon::parse('created_at')->diffInDays(Carbon::now()), $daysTillTrialEnds)
Run Code Online (Sandbox Code Playgroud)
没有出现此错误:
DateTime::__construct(): Failed to parse time string (created_at) at position 0 (c): The timezone could not be found in the database
Run Code Online (Sandbox Code Playgroud)
目的是 where 将仅显示created_at 日期为 X 天前的行。
你有没有尝试过类似的事情:
$dayAgo = 6 // where here there is your calculation for now How many days
$dayToCheck = Carbon::now()->subDays($dayAgo);
$model->whereDate("created_at", =, $dayToCheck);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
14046 次 |
最近记录: |