diff --git a/src/Illuminate/Foundation/Http/FormRequest.php b/src/Illuminate/Foundation/Http/FormRequest.php index cdf222943683..e4a1c06144c7 100644 --- a/src/Illuminate/Foundation/Http/FormRequest.php +++ b/src/Illuminate/Foundation/Http/FormRequest.php @@ -109,7 +109,7 @@ protected function getValidatorInstance() */ protected function createDefaultValidator(ValidationFactory $factory) { - $rules = $this->container->call([$this, 'rules']); + $rules = method_exists($this, 'rules') ? $this->container->call([$this, 'rules']) : []; $validator = $factory->make( $this->validationData(), $rules, diff --git a/tests/Foundation/FoundationFormRequestTest.php b/tests/Foundation/FoundationFormRequestTest.php index 0f42b51eda74..c4e5c4f11565 100644 --- a/tests/Foundation/FoundationFormRequestTest.php +++ b/tests/Foundation/FoundationFormRequestTest.php @@ -149,6 +149,15 @@ public function testValidatedMethodReturnsOnlyRequestedNestedValidatedData() $this->assertSame('bar', $request->validated('nested.foo')); } + public function testRequestCanPassWithoutRulesMethod() + { + $request = $this->createRequest([], FoundationTestFormRequestWithoutRulesMethod::class); + + $request->validateResolved(); + + $this->assertEquals([], $request->all()); + } + /** * Catch the given exception thrown from the executor, and return it. * @@ -377,3 +386,11 @@ public function authorize() return Response::allow('baz'); } } + +class FoundationTestFormRequestWithoutRulesMethod extends FormRequest +{ + public function authorize() + { + return true; + } +}