'; var_dump($this->all()); echo''; } /** * Get the validation rules that apply to the request. */ public function rules(): array { //Получаем список активных пользователей $empActiveLogins = OldMagicModels\CcEmp::select('emp_login') ->whereNotIn('emp_state', ['Уволен', 'Декрет']) ->get() ->toArray(); //Правила валидации $validationRules = [ 'id' => [ 'int' ], 'taxi_date' => [ 'date_format:Y-m-d', //Заказ можно создать только на сегодняшний или завтрашний день Rule::in([ (new DateTime())->format('Y-m-d'), (new DateTime())->modify('+1 day')->format('Y-m-d') ]), ], 'taxi_time' => [ 'required', 'string', 'regex:/^[0-9]{2}:[0-9]{2}$/', //время в формате 00:00 ], 'cancel_rqst' => 'boolean', 'emp_phone' => [ 'required', 'int', 'regex:/^(7|8)?[0-9]{10}$/' ], 'emp_login' => [ $validationRules['emp_login'] = [ 'required', 'string', 'regex:/^[a-z\-]+[0-9]*$/', //Логины ищем среди активных логинов на текущий момент Rule::in( array_map(fn($el) => $el['emp_login'], $empActiveLogins) ) ], ], 'taxi_address_from' => [ 'required', 'string', 'max: 500' ], 'taxi_address_to' => [ 'required', 'string', 'max: 500' ] ]; //Во время создания запроса поле ID не валидируется if ($this->isMethod('POST')){ $validationRules['id'] = [ 'prohibited' ]; } return $validationRules; } /** * Determine if the user is authorized to make this request. */ public function authorize(): bool { return true; } /** * Переопределение сообщений об ошибках валидации * * @return array */ public function messages(): array { return [ 'taxi_date.in' => 'Заявку на такси можно завести только на сегодняшний или завтрашний день' ]; } }