HEX
Server: LiteSpeed
System: Linux sv4.hami.host 5.14.0-611.54.3.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 7 16:31:24 EDT 2026 x86_64
User: armgroup (1008)
PHP: 8.2.32
Disabled: show_source, system, shell_exec, passthru, exec, popen, proc_open, mail, socket_create, socket_create_listen, socket_create_pair, link, dl, openlog, syslog, stream_socket_server, curl_multi_init
Upload Files
File: /home/armgroup/libs/app/Http/Livewire/Admin/ShippingPrice/Create.php
<?php

namespace App\Http\Livewire\Admin\ShippingPrice;

use App\Http\Livewire\ConvertEmptyStringsToNull;
use App\Http\Livewire\General;
use App\Models\ShippingPrice;
use Livewire\Component;

class Create extends Component
{
    use ConvertEmptyStringsToNull, General;

    public $shippingPrices = [];

    public $deleteIds = [];

    public function mount()
    {
        $this->shippingPrices = ShippingPrice::query()
            ->select('id', 'from', 'up_to', 'my_province_courier', 'my_province_express', 'neighbor_province_courier', 'neighbor_province_express', 'not_neighbor_province_courier', 'not_neighbor_province_express')
            ->get()
            ->toArray();
    }

    public function render()
    {
        return view('livewire.admin.shipping-price.create');
    }

    protected function rules()
    {
        return [
            'shippingPrices.*.from' => ['required', 'integer', 'min:0', 'max:100000000', 'distinct'],
            'shippingPrices.*.up_to' => ['nullable', 'integer', 'min:1', 'max:100000000', 'distinct', 'gt:shippingPrices.*.from', 'distinct'],
            'shippingPrices.*.my_province_courier' => ['nullable', 'integer', 'min:0', 'max:100000000'],
            'shippingPrices.*.my_province_express' => ['nullable', 'integer', 'min:0', 'max:100000000'],
            'shippingPrices.*.neighbor_province_courier' => ['nullable', 'integer', 'min:0', 'max:100000000'],
            'shippingPrices.*.neighbor_province_express' => ['nullable', 'integer', 'min:0', 'max:100000000'],
            'shippingPrices.*.not_neighbor_province_courier' => ['nullable', 'integer', 'min:0', 'max:100000000'],
            'shippingPrices.*.not_neighbor_province_express' => ['nullable', 'integer', 'min:0', 'max:100000000'],
        ];
    }

    protected $validationAttributes = [
        'shippingPrices.*.from' => 'از وزن',
        'shippingPrices.*.up_to' => 'تا وزن',
        'shippingPrices.*.my_province_courier' => 'پیک درون استانی',
        'shippingPrices.*.my_province_express' => 'پیشتاز درون استانی',
        'shippingPrices.*.neighbor_province_courier' => 'پیک استان همجوار',
        'shippingPrices.*.neighbor_province_express' => 'پیشتاز استان همجوار',
        'shippingPrices.*.not_neighbor_province_courier' => 'پیک استان غیرهمجوار',
        'shippingPrices.*.not_neighbor_province_express' => 'پیشتاز استان غیرهمجوار',
    ];

    public function addItem()
    {
        array_push($this->shippingPrices, [
            'id' => null,
            'from' => null,
            'up_to' => null,
            'my_province_courier' => null,
            'my_province_express' => null,
            'neighbor_province_courier' => null,
            'neighbor_province_express' => null,
            'not_neighbor_province_courier' => null,
            'not_neighbor_province_express' => null,
        ]);
    }

    public function removeItem($index)
    {
        if ($this->shippingPrices[$index]['id']) {
            $this->deleteIds[] = $this->shippingPrices[$index]['id'];
        }

        unset($this->shippingPrices[$index]);
    }

    public function store()
    {
        $this->validate();
        if (! count($this->shippingPrices)) {
            ShippingPrice::delete();
        } else {
            if (count($this->deleteIds)) {
                ShippingPrice::whereIn('id', $this->deleteIds)->delete();
            }

            ShippingPrice::upsert(
                $this->shippingPrices,
                ['id'],
                ['from', 'up_to', 'my_province_courier', 'my_province_express', 'neighbor_province_courier', 'neighbor_province_express', 'not_neighbor_province_courier', 'not_neighbor_province_express']
            );
        }
        saveActivity('هزینه‌های ارسال مقداردهی شد');
        $this->doneMessage();

        return redirect()->route('admin.shipping-prices.index');
    }
}