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/Brand/Edit.php
<?php

namespace App\Http\Livewire\Admin\Brand;

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

class Edit extends Component
{
    use ConvertEmptyStringsToNull, General;

    public Brand $brand;

    public $faq;

    protected $listeners = ['imageChanged'];

    public function mount()
    {
        $this->faq = $this->brand->faq ?: [];
    }

    protected function rules()
    {
        return [
            'brand.name' => 'required|string|max:250',
            'brand.slug' => 'required|string|max:250|alpha_dash|unique:brands,slug,'.$this->brand->id,
            'brand.image' => 'nullable|max:250|string',
            'brand.short_description' => 'nullable|string|max:250',
            'brand.description' => 'nullable|string|max:60000',
            'brand.sort_order' => 'nullable|integer|min:0|max:10000',
            'brand.meta_title' => 'nullable|string|max:250',
            'brand.h1' => 'nullable|string|max:250',
            'faq.*.question' => 'required|max:250',
            'faq.*.answer' => 'required|max:250',
        ];
    }

    protected $validationAttributes = [
        'faq.*.question' => 'سوال',
        'faq.*.answer' => 'جواب',
    ];

    public function addItem()
    {
        array_push($this->faq, [
            'question' => null,
            'answer' => null,
        ]);
    }

    public function removeItem($index)
    {
        unset($this->faq[$index]);
    }

    public function render()
    {
        return view('livewire.admin.brand.edit');
    }

    public function update()
    {
        $this->brand->faq = count($this->faq) ? $this->faq : null;

        $this->brand->update();

        $this->doneMessage("{$this->brand->name} با موفقیت ویرایش شد");

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

    public function imageChanged($imagePath)
    {
        $this->brand->image = ltrim(parse_url($imagePath, PHP_URL_PATH), '/');
    }
}