File: /var/www/vhost/disk-apps/sigedo-dev.allup.com.co/app/Console/Commands/SendNotification.php
<?php
namespace App\Console\Commands;
use Carbon\Carbon;
use App\Monitoring;
use App\Programming;
use App\Http\Controllers\NotificationsController;
use Illuminate\Console\Command;
class SendNotification extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'huv:sendNotification {programming_id}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Proceso automatico de envio de notificaciones';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$programming_id = $this->argument('programming_id');
$programming = Programming::where('id', $programming_id)->with('automaticprocess')->first();
$monitoring = Monitoring::create([
'programming_id' => $programming_id,
'stateprogramming_id' => 1,
'start_execution' => Carbon::now(),
]);
try {
$noti = new NotificationsController();
$noti->sendNotification($programming->automaticprocess->notification_id);
Monitoring::where('id', $monitoring->id)->update(['stateprogramming_id' => 3, 'end_execution' => Carbon::now(), 'msg' => 'Ok']);
} catch (\Exception $e) {
Monitoring::where('id', $monitoring->id)->update(['stateprogramming_id' => 2, 'end_execution' => Carbon::now(), 'msg' => $e->getMessage()]);
}
}
}