Criei um cron para envio de email a cada período de tempo. Porém como testar o funcionamento ?
Codigo
<?php
namespace App\Console\Commands;
namespace App\Console\Commands\EnvioEmailBlCron;
use Illuminate\Console\Command;
class envioEmailBIcron extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'envioEmailBI:cron';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command Email';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
//Pegar os dados no banco
$sql = ' select * from payments as P, receipts as R ';
$sql .= ' where P.created_at < CURRENT_DATE AND P.created_at < CURRENT_DATE -1';
$sql .= ' OR R.created_at < CURRENT_DATE AND R.created_at < CURRENT_DATE -1';
//pega os dados no banco
$dados = \DB::select($sql);
//envio email
Mail::send('emails.BI', $dados, function ($message) {
$message->to(Input::get('email'));
});
// executando as funções de envio de e-mail
$this->info('Example Cron comando rodando com êxito');
}
}
ConsoleKernel.php
<?php
namespace App\Units;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel;
class ConsoleKernel extends Kernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
//Commands\Inspire::class,
Commands\EnvioEmailBICron::class
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
*/
protected function schedule(Schedule $schedule)
{
//configuração do cron
$schedule->command('inspire')->dailyAt('01:00');
$schedule->command('EnvioEmailBICron:cron')->daily(); // email diários
}
/**
* Register the Closure based commands for the application.
*/
protected function commands()
{
}
}