如何在开始时间的一小时之前显示数据,并在一小时之后隐藏结束时间

问题描述 投票:0回答:2

我希望在开始时间的一小时之前显示按钮或链接,并在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
php laravel laravel-5.5
2个回答
1
投票

您应该遵循以下几点:

  1. 使用Carbon而不是php函数。
  2. 加载按钮的最佳选择是AJAX。页面加载时不检查。
  3. 使用AJAX通过检查开始和结束时间之间的当前时间在DOM中添加按钮。
  4. 使用Blad你ajax控制器方法加载按钮
  5. 通过使用Ajax没有人可以调整你的按钮的URL,也可以将UUID添加到按钮url,所以如果有人复制你的按钮,下次将不会使用。

0
投票

你可以使用碳:

@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将自动解析碳的日期。

© www.soinside.com 2019 - 2024. All rights reserved.