Develop a small module that basically sends a congratulatory email to users on their birthday, everything works fine but now I would like this email to be sent automatically every day at midnight, following a tutorial along with the documentation of laravel cree a comando
that makes me this function, register this in kernel
but now I'm not sure how to continue.
According to the tutorial that I follow, I have to start the Laravel Scheduler
to run the cron, according to this line of code.
* * * * * php /path/to/artisan schedule:run 1>> /dev/null 2>&1
But I'm not sure if this is executed on the server console where my system is hosted. It's the first time I try this and I do not know how to proceed.
This is my file where I register the command:
class HappyBirthday extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'emails:birthday';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Envia un email de Cumpleaños a los usuarios';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$users = Employee::where('CONDICION', '=', 'A')->get();
foreach($users as $user){
$toDay = Carbon::now('America/Caracas');
$toDay = $toDay->format('m-d');
$dateUser = new Carbon($user->FECHA_NAC);
$dateUser = $dateUser->format('m-d');
if($toDay == $dateUser){
Mail::to($user->EMAIL)->send(new Birthday($user));
}
}
$this->info('Los mensajes de felicitacion han sido enviados correctamente');
}
}
And so I execute the schedule
from my kernel.php
.
$schedule->command('emails:birthday')->daily()->timezone('America/Caracas');
How should you proceed so that my command runs daily at midnight?