dev-think-one /
laravel-iprosoftware-sync
| 1 | <?php |
||
| 2 | |||
| 3 | namespace IproSync\Jobs\Settings; |
||
| 4 | |||
| 5 | use Illuminate\Bus\Queueable; |
||
| 6 | use Illuminate\Contracts\Queue\ShouldQueue; |
||
| 7 | use Illuminate\Foundation\Bus\Dispatchable; |
||
| 8 | use Illuminate\Queue\InteractsWithQueue; |
||
| 9 | use Illuminate\Queue\SerializesModels; |
||
| 10 | use IproSync\Models\Attribute; |
||
| 11 | use LaravelIproSoftwareApi\IproSoftwareFacade; |
||
| 12 | |||
| 13 | class AttributesPull implements ShouldQueue |
||
| 14 | { |
||
| 15 | use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 16 | |||
| 17 | public function handle() |
||
| 18 | { |
||
| 19 | $response = IproSoftwareFacade::getAttributesList()->onlySuccessful(); |
||
| 20 | |||
| 21 | $groups = $response->json(); |
||
| 22 | if (is_array($groups) && !empty($groups)) { |
||
| 23 | foreach ($groups as $items) { |
||
| 24 | foreach ($items['Values'] ?? [] as $item) { |
||
| 25 | if (!isset($item['Id'])) { |
||
| 26 | continue; |
||
| 27 | } |
||
| 28 | Attribute::firstOrNew(['id' => $item['Id']], ) |
||
| 29 | ->fill([ |
||
| 30 | 'name' => $item['Name'], |
||
| 31 | 'type' => $items['Name'], |
||
| 32 | ]) |
||
| 33 | ->fillPulled() |
||
| 34 | ->save(); |
||
| 35 | } |
||
| 36 | } |
||
| 37 | } |
||
| 38 | } |
||
| 39 | } |
||
| 40 |