HEX
Server: nginx/1.18.0
System: Linux test-ipsremont 5.4.0-214-generic #234-Ubuntu SMP Fri Mar 14 23:50:27 UTC 2025 x86_64
User: ips (1000)
PHP: 8.0.30
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/ipsremont-demo/app/Http/Requests/Repair/CreateRequest.php
<?php

namespace App\Http\Requests\Repair;

use App\Helpers\UserHelper;
use App\Http\Requests\Request;

/**
 * @property int $order_id
 * @property string $name
 * @property string $email
 * @property string $phone
 * @property string $additional_info
 * @property string $serial_number
 * @property string $device_id
 * @property string $sold_at
 * @property string $repair_date
 * @property string $inner_nbr
 * @property string $address
 * @property string $custom_component_sku
 * @property string $custom_component_name
 * @property string $use_catalog_component
 */
class CreateRequest extends Request
{

    public function rules(): array
    {
        $rules = [];
        $user = UserHelper::getUser();
        if ($user->isService()) {
            $rules += [
                'name' => ['string', 'required'],
                'email' => ['email', 'required'],
                'phone' => ['string', 'required'],
            ];
        } else {
            $rules += [
                'name' => ['string', 'nullable'],
                'email' => ['email', 'nullable'],
                'phone' => ['string', 'nullable'],
            ];
        }

        $rules += [
            'additional_info' => ['string', 'required'],
            'serial_number' => ['string', 'required'],
            'sold_at' => ['date_format:Y-m-d', 'nullable', 'required_unless:pre_sale,1'],
            'repair_date' => ['required', 'date_format:Y-m-d'],
            'inner_nbr' => ['string', 'nullable'],
            'address' => ['string', 'nullable'],
            'device_id' => ['integer', 'nullable', 'required_if:use_catalog_component,1'],
        ];

        return $rules;
    }

    protected function prepareForValidation()
    {
        $this->merge([
            'phone' => preg_replace('/[^0-9]/', '', $this->phone),
            'sold_at' => $this->dateFromJs($this->sold_at),
            'repair_date' => $this->dateFromJs($this->repair_date),
        ]);
    }

    public function messages(): array
    {
        return [
            'sold_at.required_unless' => 'Поле Продано обязательно для заполнения если не выбран Предторг',
        ];
    }

}