Answer the question
In order to leave comments, you need to log in
Laravel. How to delete a record if a day or more has passed since created_at?
Laravel 5.2.
How to make sure that those records in the database that have passed 1 day or more since their creation are deleted?
Thanks in advance.
Answer the question
In order to leave comments, you need to log in
- Create a command for artisan
- Hang the command on cron
- Write a selection of records and delete them. Something like this:
$records = Model::whereDate('created_at', '<', Carbon::today()->toDateSting())->get();
$count = $records->count();
foreach ($records as $record) {
$record->delete();
}
if ($count > 0) {
$this->info("Удалено {$count} записей.");
}
Create a task that will check this whole thing and delete records.
That way
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question