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

namespace App\Http\Livewire\Admin\Author;

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

class Edit extends Component
{
    use ConvertEmptyStringsToNull, General;

    public Author $author;

    public $faq;

    protected $listeners = ['imageChanged'];

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

    protected function rules()
    {
        return [
            'author.name' => 'required|string|max:250',
            'author.slug' => 'required|string|max:250|alpha_dash|unique:authors,slug,'.$this->author->id,
            'author.image' => 'nullable|max:250|string',
            'author.short_description' => 'nullable|string|max:250',
            'author.description' => 'nullable|string|max:60000',
            'author.sort_order' => 'nullable|integer|min:0|max:10000',
            'author.meta_title' => 'nullable|string|max:250',
            'author.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.author.edit');
    }

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

        $this->author->update();

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

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

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