2

I have an issue with this statement can some one help

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>

2 Answers2

4

Laravel automatically wrap created_at to Carbon instance, and Carbon instance you can easly add year using addYear() function. See Documentation https://carbon.nesbot.com/docs/#api-addsub,
Corrected code is

date('d F Y', strtotime($vehicle->created_at->addYear()))

for more good practice you can use as @Rafael suggested this code for get same result

<td>{{ $vehicle->created_at->format('d F Y') }}</td>
<td>{{ $vehicle->created_at->addYear()->format('d F Y') }}</td> 
Davit Zeynalyan
  • 8,418
  • 5
  • 30
  • 55
1

+1 year should concat with $vehicle->created_at instead of passing as third parameter to date function. Code:

date('d F Y', strtotime($vehicle->created_at . " +1 year") );
Lovepreet Singh
  • 4,792
  • 1
  • 18
  • 36