I have created a cronjob for age calculation named "cronAge" using command
php artisan make:command cronAge
Below is my Employee Model:
class Employee extends Model
{
protected $primaryKey = 'tag_no';
public $incrementing = false;
protected $fillable = [
'tag_no',
'emp_type',
'age',
'date_of_birth',
];
}
I am planning to call the cronjob monthly.
protected function schedule(Schedule $schedule)
{
$schedule->command('cronAge')
->monthly();
}
This is my function: Its not a working code. It only shows the logic for calculating the age.
public function handle()
{
$emp= new Employee();
$today = new Date();
$birth_day = $emp->date_of_birth;
if ($today.getFullYear() - $birth_day.getFullYear() == 1) {
if ($today.getMonth() == $birth_day.getMonth()
&& $today.getDate() == $birth_day.getDate()) {
$emp->age = $emp->age+1;
}
}
}
So how to implement my logic in the function. Is the logic rite? And please help me in this. I'm new to this cronjob topic and i donno much.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire