0

我正在使用碳来获取今天的日期并将其格式化为 laravel 刀片模板,这根本不是问题,但是在增加时我遇到了问题

我目前正在测试仅添加一天,但我想实际为今天和接下来的 7 天创建表头。

在我的刀片中,我有:

<?php 
use Carbon\Carbon;
$date = Carbon::now()->format('m/d/Y');
?>

<thead>
  <tr>
    <th>{{$date}}</th>
    <th>{{$date->addDay()}}</th>
  </tr>
</thead>

但它是说我正在调用addDay一个字符串,这是有道理的,因为我正在以这种方式格式化日期。

有没有办法可以保持这种 mm/dd/yyyy 的日期格式,但也可以在该格式上使用 addDay 之类的东西创建一个循环?我只想在接下来的 7 天内递增并将这些日期用作表格标题

4

1 回答 1

2

你能试试这个吗

<?php 
use Carbon\Carbon;
$format = 'm/d/Y';
$date = Carbon::now();
?>

<thead>
  <tr>
    <th>{{$date->format($format)}}</th>
    <th>{{$date->addDay()->format($format)}}</th>
  </tr>
</thead>

于 2021-08-12T02:33:52.900 回答