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

namespace App\Http\Livewire\Admin\Point;

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

class Edit extends Component
{
    use ConvertEmptyStringsToNull, General;

    public Point $point;

    public $type;

    public function mount()
    {
        $this->type = (int) ($this->point->amount > 0);
        $this->point->amount = abs($this->point->amount);
    }

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

    protected function rules()
    {
        return [
            'point.description' => 'required|string|max:60000',
            'type' => 'required|boolean',
            'point.amount' => ['required', 'integer', 'min:1', 'max:100000000000', function ($attribute, $value, $fail) {
                if (! $this->type && $this->point->user->point - $this->point->getOriginal('amount') < $value) {
                    return $fail('امتیاز کاربر نمی‌تواند منفی باشد.');
                }
            }],
        ];
    }

    public function update()
    {
        $this->validate();

        $this->point->amount = $this->type ? $this->point->amount : $this->point->amount * -1;
        $this->point->update();

        saveActivity("یک مورد از امتیازات {$this->point->user->name} را ویرایش کرد", $this->point);

        $this->doneMessage();

        return redirect()->route('admin.user.points.index', $this->point->user);
    }
}