123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <?php
- namespace App\Distributor\Repositories;
- use App\Models\DistProductImage as Model;
- use Dcat\Admin\Repositories\EloquentRepository;
- class DistProductImage extends EloquentRepository
- {
-
- protected $eloquentClass = Model::class;
-
- public static function formatData($productId, $images)
- {
- $existingImages = Model::where('product_id', $productId)->get();
-
- $result = [];
-
- foreach ($existingImages as $existingImage) {
- if (!in_array($existingImage->image_url, $images)) {
- $result[] = [
- 'id' => $existingImage->id,
- 'image_url' => $existingImage->image_url,
- '_remove_' => 1,
- ];
- }
- }
-
- foreach ($images as $image) {
- $found = $existingImages->firstWhere('image_url', $image);
- if (!$found) {
- $result[] = [
- 'id' => 0,
- 'image_url' => $image,
- ];
- }
- }
- return $result;
- }
- }
|