Delete Rows Older Than 30 Days Using Laravel Eloquent

For a purpose where you want to delete posts older than specific days. With Laravel’s eloquent ORM, you can create a function for the task.

By creating a simple easy function, you can manually call it to do action.

For the example here we suppose it is 30 days older posts, to delete using laravel function.

Post::whereDate('create_at', '<=', now()->subDays(30)->delete();

Final function

public function deleteOld()
{
     Post::whereDate('create_at', '<=', now()->subDays(30)->delete();
}

Related Posts