PHP 碳类更改我的原始变量值
2022-08-30 10:04:19
我正在尝试在我正在创建的日历类型中制作一些导航按钮,并且我正在使用碳来创建日期。
这是控制器中的代码:
if ($date == null) {
$date = \Carbon\Carbon::now();
} else {
$date = \Carbon\Carbon::createFromFormat('Y-m-d', $date);
}
$navDays = [
'-7Days' => $date->subDay('7')->toDateString(),
'-1Day' => $date->subDay('1')->toDateString(),
'Today' => $date->today()->toDateString(),
'+1Day' => $date->addDay('1')->toDateString(),
'+7Days' => $date->addDay('7')->toDateString()
];
然后我是我的观点,我正在这样做:
@foreach($navDays as $key => $i)
<li>
<a href="/planner/bookings/{{ $i }}" class="small button">
{{ $key }}
</a>
</li>
@endforeach
问题是,碳似乎在数组创建过程中改变了$date,因为这些是我得到的日期(设置为):$date
2015-11-29
<ul class="button-group even-5">
<li><a href="/planner/bookings/2015-11-22" class="small button">-7Days</a></li>
<li><a href="/planner/bookings/2015-11-21" class="small button">-1Day</a></li>
<li><a href="/planner/bookings/2015-12-22" class="small button">Today</a></li>
<li><a href="/planner/bookings/2015-11-22" class="small button">+1Day</a></li>
<li><a href="/planner/bookings/2015-11-29" class="small button">+7Days</a></li>
</ul>
有谁知道我做错了什么?