How to add days to datetime field in Laravel?
For example,
there is a
updated_at
articles
$article = Article::find(1);
$updated_at=$article->updated_at;
updated_at
Carbon
$expired_at=Carbon::now()->addDays(30);
Since updated_at
and created_at
fields are automatically cast to an instance of Carbon
you can just do:
$article = Article::find(1);
$article->updated_at->addDays(30);
// $article->save(); If you want to save it
Or if you want it in a separate variable:
$article = Article::find(1);
$updated_at = $article->updated_at;
$updated_at->addDays(30); // updated_at now has 30 days added to it