How to Delete All Records Older Than 30 Days in Laravel?
In this quick example, let's see laravel delete all records older than 30 days. This example will help you how to delete all records older than 30 days in laravel. I’m going to show you about laravel delete records older than 30 days. This tutorial will give you a simple example of laravel delete old records 30 days example. So, let's follow a few steps to create an example of laravel delete all 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. you need to just setup in your cron. so, let's see the simple query code.
class PostController extends Controller
* Write code on Method
* @return response()
public function index(Request $request)
Post::whereDate('created_at', '<=', now()->subDays(30))->delete();
I hope it can help you...
We are Recommending you
- Laravel 10 Enum Model Attribute Casting Example
- Laravel 10 Model Observers Example Tutorial
- Laravel 10 Model Events Example Tutorial
- How to Add Custom Attribute in Laravel Model?
- Get Array of Ids from Eloquent Models in Laravel
- Laravel Eloquent Find by Column Name Example
- Laravel Group By with Min Value Query Example
- Laravel Eloquent doesntHave() Condition Example
- Laravel Eloquent orWhereHas() Condition Example
- Laravel Eloquent Group By with Month and Year Example
- Laravel Eloquent When Condition Example
- Laravel Eloquent firstOr() Example
- Laravel Eloquent withMin(), withMax() and withAvg() Example
- Laravel Eloquent withSum() and withCount() Example