In this tutorial i’m going to learn how to delete all records older than 30 days. In this blog i have to mentioned in very easy to delete the records older than 30 days. If you want to keep only last 30 days records in your laravel application then i will give simple database query to delete all records older than 30 days in laravel.
Use below function to delete
public function index(Request $request)
{
Post::whereDate('created_at', '<=', now()->subDays(30))->delete();
}
I hope its helpful for you šš