22 lines
528 B
PHP
Executable File
22 lines
528 B
PHP
Executable File
<?php
|
|
|
|
namespace App\Services\Dashboard\Region;
|
|
|
|
use App\Models\Region;
|
|
|
|
class RegionService
|
|
{
|
|
public static function deliveryPrice(Region $region, $data)
|
|
{
|
|
$toDelete = $region->deliveryPrice()->whereNotIn('power_id', array_column($data, 'power_id'))->get();
|
|
$toDelete->each->delete();
|
|
|
|
foreach ($data as $item) {
|
|
$region->deliveryPrice()->updateOrCreate(
|
|
['power_id' => $item['power_id']],
|
|
['price' => $item['price']]
|
|
);
|
|
}
|
|
}
|
|
}
|