Answers for "Laravel Scheduler"

PHP
1

laravel scheduler run

php artisan schedule:list
php artisan schedule:run
Posted by: Guest on May-08-2021
2

laravel 8 scheduler

// 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

test laravel scheduler

Set the cron to run after every minute:
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
  
Then inisde you kernel.php
//For every minute
$schedule->call(function () {
	Log::info('I ran after every 1 minute');
})->everyMinute();
//For every five minute
$schedule->call(function () {
	Log::info('I ran after every 5 minute');
})->everyFiveMinutes();
Posted by: Guest on December-12-2020
0

laravel run schedule locally

php artisan schedule:work
Posted by: Guest on October-05-2021
2

Laravel Scheduler

$schedule->call(function () {
            DB::table('users')->whereYear('last_login_at','<',date('Y')-1)->delete();
        })->daily();
Posted by: Guest on May-10-2020

Browse Popular Code Answers by Language