K
K
Kirill Trifonov2016-04-28 16:11:24
MySQL
Kirill Trifonov, 2016-04-28 16:11:24

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

2 answer(s)
D
D', 2016-04-28
@Flancyk

- 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} записей.");
}

S
Stanislav Pochepko, 2016-04-28
@DJZT

Create a task that will check this whole thing and delete records.
That way

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question