Laravel How to delete database data after 5 minutes of adding?
Schema::create('listings', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('country');
$table->string('date');
$table->timestamps();
});
CodePudding user response:
Just use this in the scheduler.(or can call a event)
This gets the record for the last 5 minutes and deletes the data.
$minutes = Carbon::now()->subMinutes( 5 );
Listing::where('created_at', '<=', $minutes)->delete();
And schedule it to
everyMinute()
Note: I assumed you have a model called Listing
or change according to it.
CodePudding user response:
You can use cron job for this. You have to set cron job time to execute after 5 minutes and removed database which was created before 5 minutes.
Please refere:- https://laravel.com/docs/9.x/scheduling