我希望在开始时间的一小时之前显示按钮或链接,并在Laravel刀片中的结束时间之后隐藏一小时。
我使用的是Laravel 5.5。
我尝试:
$ptime = date('h:i a',strtotime('-1 hour',strtotime($scheduleGroupWorkout->schedule_start_at)));
$ctime = date('h:i a', strtotime($scheduleGroupWorkout->schedule_start_at));
$cendtime = date('h:i a', strtotime($scheduleGroupWorkout->schedule_end_at));
$eendtime = date('h:i a',strtotime('+1 hour',strtotime($scheduleGroupWorkout->schedule_end_at)));
Laravel Blade
@if(strtotime($ctime) < strtotime($ptime) && strtotime($eendtime) < strtotime($cendtime))
<div class="schedule-time-btn">
<a href="#" target="_blank" class="btn btn-success">Join</a>
</div>
@endif
您应该遵循以下几点:
你可以使用碳:
@if(Carbon::parse($ctime)->lt(Carbon::parse(ptime)) && Carbon::parse($eendtime)->lt(Carbon::parse(cendtime)))
<div class="schedule-time-btn">
<a href="#" target="_blank" class="btn btn-success">Join</a>
</div>
@endif
如果从模型中检索数据,可以将schedule_start_at添加到模型$ dates数组中:
在你的模型中:
$dates = ['schedule_start_at','schedule_end_at'];
然后laravel将自动解析碳的日期。