Viewing file: ProductRequest.php (1.57 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
namespace App\Jobs;
use App\Models\Category; use GuzzleHttp\Client; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; use Illuminate\Support\Str;
class ProductRequest { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $timeout=60 * 3; private $category_code; /** * Create a new job instance. * * @return void */
public function __construct($category_code) { $this->category_code = $category_code;
}
/** * Execute the job. * * @return void */ public function handle() {
try { $category_code= $this->category_code;
$client = new Client(['verify'=>false]); $response = $client->get("https://dev.lapakgaming.com/api/all-products", [ 'headers' => [ 'TOKEN' => '{{PHP_PATH}}' ] ]);
$response= $response->getBody()->getContents(); $response=json_decode($response);
if($response && isset($res->data)){
foreach ($res->data as $product){
SyncProduct::dispatch($product);
}
}
}catch(\Exception $e){ Log::error($e->getMessage()); }
}
public function failed($exception) { Log::info($exception);
} }
|