Laravel. How to delete a record, if created_at hosted the day and more?

Laravel 5.2.
How to make sure to remove those records in the database, whose creation was 1 day or more?
Thanks in advance.
July 12th 19 at 17:14
2 answers
July 12th 19 at 17:16
- Create command to artisan
- Hang command on Kron
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) {

if ($count > 0) {
 $this->info("Removed {$count} records.");
Thank you, not immediately understood, it was necessary in late Model::whereDate('created_at', '<', Carbon::today()->toDateSting());
add ->get(); - rollin_Colli commented on July 12th 19 at 17:19
Can be even easier:

Model::where(...)->delete(); - Lilian.Lubowit commented on July 12th 19 at 17:22
: Yes, corrected. Unfinished. - destany34 commented on July 12th 19 at 17:25
July 12th 19 at 17:18
To create a job that will test it, and delete records.
You are here

Find more questions by tags LaravelPHPMySQL