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

namespace App\Http\Livewire\Account\Ticket;

use App\Enums\TicketStatus;
use App\Http\Livewire\ConvertEmptyStringsToNull;
use App\Http\Livewire\General;
use App\Models\Ticket;
use App\Models\TicketAttachment;
use App\Models\TicketMessage;
use Illuminate\Support\Facades\DB;
use Livewire\Component;
use Livewire\WithFileUploads;

class Edit extends Component
{
    use ConvertEmptyStringsToNull, General, WithFileUploads;

    public $ticketMessage;

    public $items = [];

    public $ticket;

    public function render()
    {
        return view('livewire.account.ticket.edit');
    }

    public function addItem()
    {
        if (count($this->items) < 5) {
            array_push($this->items, [
                'name' => null,
                'path' => null,
            ]);
        }
    }

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

    protected function rules()
    {
        return [
            'ticketMessage' => 'required|string|min:3|max:60000',
            'items' => 'nullable|array|max:5',
            'items.*.name' => 'sometimes|required|string|max:250',
            'items.*.path' => 'required|sometimes|mimes:doc,pdf,docx,zip,jpg,png,jpeg|max:20483',
        ];
    }

    public function update()
    {
        $this->validate();
        $status = $this->ticket->status->is(TicketStatus::OPEN) ? TicketStatus::OPEN : TicketStatus::CUSTOMER_REPLY;
        DB::transaction(function () use ($status) {
            Ticket::where('id', $this->ticket->id)->update(['status' => $status]);
            $message = TicketMessage::create([
                'user_id' => auth()->id(),
                'ticket_id' => $this->ticket->id,
                'body' => $this->ticketMessage,
            ]);
            if (count($this->items)) {
                $folder = auth()->id().'/'.date('Y/m');
                foreach ($this->items as $item) {
                    if ($name = $item['path']->store('attachments/'.$folder)) {
                        $attachments[] = [
                            'message_id' => $message->id,
                            'title' => $item['name'],
                            'mime' => $item['path']->extension(),
                            'path' => $name,
                        ];
                    }
                }
                TicketAttachment::insert($attachments);
            }
        });
        $this->doneMessage('Updated Successfully');

        return redirect()->route('account.tickets.edit', $this->ticket->slug);
    }
}