php - How to set up task scheduling in Laravel 4? -
i've website made in laravel 4.2 , have monthly membership 30 credits. if user doesn't use of them, should expire @ valid_till
date.
i wish have piece of code run @ 12 every night , set credit 0 in everyone's account who's valid_till
date equal yesterday or before that.
if there task scheduling in laravel 5.1, runs function on particular time of day daily, perfect.
know cron can set in laravel 4.2, using commands i'm unable understand how use in case?
create file following in app/commands, replace comment in fire method update function.
<?php use illuminate\console\command; use symfony\component\console\input\inputoption; use symfony\component\console\input\inputargument; class setcredittozero extends command { /** * console command name. * * @var string */ protected $name = 'set:zero'; /** * console command description. * * @var string */ protected $description = 'command description.'; /** * create new command instance. * * @return void */ public function __construct() { parent::__construct(); } /** * execute console command. * * @return mixed */ public function fire() { // update function here } /** * console command arguments. * * @return array */ protected function getarguments() { return [ ]; } /** * console command options. * * @return array */ protected function getoptions() { return [ ]; } }
register command in app/start/artisan.php
artisan::add(new setcredittozero);
now set cronjob using command on terminal
crontab -e
and in file set cronjob line
0 0 * * * /usr/bin/php /path/to/laravel/basedir/artisan set:zero
and should go
Comments
Post a Comment