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

59 lines
1.4 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;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use App\Models\WorkOrder\Reply as WorkOrderReply;
use Log;
2022-08-19 15:27:57 +00:00
class Reply implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $reply;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(WorkOrderReply $reply)
{
//
$this->reply = $reply;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
//
$this->reply->load(['workOrder', 'user']);
$this->reply->workOrder->load(['module']);
2022-08-19 15:27:57 +00:00
$http = Http::remote($this->reply->workOrder->module->api_token, $this->reply->workOrder->module->url);
$reply = $this->reply->toArray();
$response = $http->post('work-orders/' . $this->reply->workOrder->id . '/replies', $reply);
2022-08-19 15:27:57 +00:00
if ($response->successful()) {
$this->reply->is_pending = false;
} else {
$this->reply->is_pending = true;
}
$this->reply->save();
}
}