我对此声明有疑问,可以帮忙
foreach ($vehicles as $vehicle)
<tr>
<td>{{ date('d F Y', strtotime($vehicle->created_at)) }}</td>
<td>{{ date('d F Y', strtotime($vehicle->created_at), " +1 year") }}</td>
答案 0 :(得分:1)
Laravel自动将created_at
包装到Carbon
实例中,而Carbon实例则可以使用addYear()
函数轻松地添加年份。请参阅文档https://carbon.nesbot.com/docs/#api-addsub,
更正的代码是
date('d F Y', strtotime($vehicle->created_at->addYear()))
为了获得更好的实践,您可以使用 @Rafael 建议此代码获得相同的结果
<td>{{ $vehicle->created_at->format('d F Y') }}</td>
<td>{{ $vehicle->created_at->addYear()->format('d F Y') }}</td>
答案 1 :(得分:1)
+1 year
应该与$vehicle->created_at
连接,而不是作为第三个参数传递给date
函数。
代码:
date('d F Y', strtotime($vehicle->created_at . " +1 year") );