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>
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>
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>
+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") );