laravel 8 delete record after given specific time
// app/Console/Kernel.php
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')->hourly();
$schedule->call(function () {
DB::table('tbl_logs')->where('created_at', '<=', Carbon::now()->toDateTimeString())->delete();
})->monthly()->evenInMaintenanceMode(); // this query will run every month, read official documentation for detail
}
// run this on your terminal:
php artisan shedule:work
// how about when my laravel project was deployed on live server / web hosting?
// it's not funny when i must connect SSH to server many times just for run that command.
// here my solution:
// 1. connect to your server
// 2. type:
crontab -e
// add these following line:
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
// save and done.
// read official documentation about "scheduling" for more detail