app/Console/Kernel.php dosyasındaki schedule metodunda belirtilir.protected function schedule(Schedule $schedule)
{
$schedule->call(function () {
DB::table('recent_users')->delete();
})->daily();
}
schedule:list artisan komutu bir sonraki scheduled taskler neler onu gösterir.
php artisan schedule:list
php artisan list ile görebiliriz.php artisan make:command örnek olarak
php artisan make:command DailyMessage
bunu yazdıktan sonra app/Console/Commands içinde DailyMessage.php diye bir command dosyası oluşur.
$signature'a düzgün isim vermek çok önemli. Neticede console'dan bu isimle çağrılacak. O nedenle anlamlı bir isimle değiştiriyorum.
protected $signature = "message:daily";
hatta derscription'ı da düzeltsek terminalde php artisan list dediğimiz zaman message sekmesinde daily commandini görebiliriz.
handle() fonksiyonunda bir iş yapmamız lazım. Buraya basitçe birşey yazalım.
public function handle()
{
echo 'This is my first basic scheduler';
}
bunu yazdıktan sonra Terminal'de php artisan message:daily dediğimizde tek seferlik bu komut çalışır ve mesajımızı terminale basar.
schedule() metoduna Closure yerine oluşturduğumuz command'i de verebiliriz.
protected function schedule(Schedule $schedule)
{
$schedule->command('message:daily')->hourly();
}
protected function schedule(Schedule $schedule)
{
$schedule->command('message:daily')
->everyMinute()
->appendOutputTo('scheduler.log');
}
withoutOverlapping() metodunu kullanabiliriz.
protected function schedule(Schedule $schedule)
{
$schedule->command('emails:send')
->daily()
->withoutOverlapping();
}
php artisan schedule:work komutunu çalıştırmak.schedule:run komutunu her dakika çalıştırmak.cd /home/forge/name-of-site-directory(example.com) && php artisan schedule:run >> /dev/null 2>&1