Lae/app/Jobs/Remote/WorkOrder/WorkOrder.php

54 lines
1.3 KiB
PHP
Raw Normal View History

2022-08-19 15:27:57 +00:00
<?php
namespace App\Jobs\Remote\WorkOrder;
use Illuminate\Bus\Queueable;
use Illuminate\Support\Facades\Http;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
2022-09-08 16:12:02 +00:00
// use Illuminate\Contracts\Queue\ShouldBeUnique;
2022-08-19 15:27:57 +00:00
use App\Models\WorkOrder\WorkOrder as WorkOrderWorkOrder;
class WorkOrder implements ShouldQueue
{
2022-09-08 16:12:02 +00:00
use InteractsWithQueue, Queueable, SerializesModels;
2022-08-19 15:27:57 +00:00
protected $workOrder, $type;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(WorkOrderWorkOrder $workOrder, $type = 'post')
{
//
$this->workOrder = $workOrder;
$this->type = $type;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$this->workOrder->load(['module']);
2022-08-19 15:27:57 +00:00
$http = Http::remote($this->workOrder->module->api_token, $this->workOrder->module->url);
if ($this->type == 'put') {
$response = $http->put('work-orders/' . $this->workOrder->id, $this->workOrder->toArray());
} else {
$response = $http->post('work-orders', $this->workOrder->toArray());
}
if (!$response->successful()) {
$this->workOrder->status = 'error';
}
$this->workOrder->save();
}
}