Answers for "laravel 8 cronjob"

PHP
2

laravel 8 cronjob

// 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
Posted by: Guest on October-20-2021
0

laravel cronjob

//App\Console\Kernel

protected function schedule(Schedule $schedule)
    {
        $schedule->call(function () {
            DB::table('recent_users')->delete();
        })->daily();
    }
Posted by: Guest on June-21-2021

Browse Popular Code Answers by Language