将 day/incrementing 添加为碳格式日期

Adding day/incrementing with a carbon formatted date

我正在使用 carbon 获取今天的日期并将其格式化为 laravel blade 模板,这根本不是问题,但是当涉及到递增时,我有一个问题

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

在我的 blade 我有:

<?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 天并将这些日期用作 table headers

你能试试这个吗

<?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>