Viewing file: SyncCategory.php (2.17 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
namespace App\Jobs;
use App\Models\Category; 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 SyncCategory implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $timeout=60 * 3; private $response; /** * Create a new job instance. * * @return void */
public function __construct($response_data) { $this->response = $response_data;
}
/** * Execute the job. * * @return void */ public function handle() {
try { $category = $this->response;
if($category) {
Category::updateOrCreate( // First parameter: Attributes to find the record [ 'name' => $category->name, 'country_code' => $category->country_code ], // Second parameter: Values to update or create [ 'name' => $category->name, 'slug' => Str::slug($category->name, '-'), 'code' => $category->code, 'status' => $category->check_id, 'country_code' => $category->country_code, 'is_feature' => 1, 'meta_keywords' => $category->name, 'variant' => $category->variant, 'forms' => json_encode($category->forms), 'servers' => json_encode($category->servers), 'meta_descriptions' => $category->name, ] ); }
}catch(\Exception $e){ Log::error($e->getMessage()); }
}
public function failed($exception) { Log::info($exception);
} }
|