From fd5dbfb4b03e75c53d5b6988c25f269d874755d3 Mon Sep 17 00:00:00 2001 From: Deeka Wong Date: Tue, 24 Oct 2023 10:09:30 +0800 Subject: [PATCH 1/2] Make rules method in FormRequest optional (#6228) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 李铭昕 <715557344@qq.com> --- src/Request/FormRequest.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Request/FormRequest.php b/src/Request/FormRequest.php index ce96b80..6f5a72f 100755 --- a/src/Request/FormRequest.php +++ b/src/Request/FormRequest.php @@ -104,6 +104,11 @@ public function setContainer(ContainerInterface $container): static return $this; } + public function rules(): array + { + return []; + } + /** * Get the validator instance for the request. */ @@ -198,7 +203,7 @@ protected function getContextValidatorKey(string $key): string */ protected function getRules(): array { - $rules = call_user_func_array([$this, 'rules'], []); + $rules = $this->rules(); $scene = $this->getScene(); if ($scene && isset($this->scenes[$scene]) && is_array($this->scenes[$scene])) { return Arr::only($rules, $this->scenes[$scene]); From 00c517320e4d38c873c83529ef10c0060aad0b9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=A3=E8=A8=80=E5=B0=B1=E6=98=AFSiam?= <59419979@qq.com> Date: Tue, 24 Oct 2023 11:14:35 +0800 Subject: [PATCH 2/2] Revert form request (#6229) --- src/Request/FormRequest.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Request/FormRequest.php b/src/Request/FormRequest.php index 6f5a72f..87f86ff 100755 --- a/src/Request/FormRequest.php +++ b/src/Request/FormRequest.php @@ -104,11 +104,6 @@ public function setContainer(ContainerInterface $container): static return $this; } - public function rules(): array - { - return []; - } - /** * Get the validator instance for the request. */ @@ -203,7 +198,7 @@ protected function getContextValidatorKey(string $key): string */ protected function getRules(): array { - $rules = $this->rules(); + $rules = method_exists($this, 'rules') ? call_user_func_array([$this, 'rules'], []) : []; $scene = $this->getScene(); if ($scene && isset($this->scenes[$scene]) && is_array($this->scenes[$scene])) { return Arr::only($rules, $this->scenes[$scene]);