Skip to content

Commit 5b37205

Browse files
committed
strip closures
1 parent 9b2e648 commit 5b37205

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/Commands/GenerateFormRequestsCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ protected function parseRules(FormRequest $formRequest) {
8888
})
8989
// Strip array value types (e.g., rule_array.*) because we don't support that yet
9090
->reject(fn($v, $k) => str_contains($k, '.*'))
91+
// Strip any rules that are closures or invokable objects
92+
->reject(fn($v) => collect($v['rules'])->contains(fn($rule) => is_object($rule)))
9193
->map(function ($item, $field) use ($mappings) {
9294
$isNullable = in_array('nullable', $item['rules']);
9395
$isSometimes = in_array('sometimes', $item['rules']);

workbench/app/Http/Requests/TestRequest2.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Http\Requests;
44

5+
use Closure;
56
use Illuminate\Foundation\Http\FormRequest;
67

78
class TestRequest2 extends FormRequest
@@ -12,7 +13,12 @@ class TestRequest2 extends FormRequest
1213
public function rules(): array
1314
{
1415
return [
15-
'just_a_string' => 'boolean',
16+
'just_a_string' => 'boolean',
17+
'with_function' => [
18+
function (string $attr, mixed $value, Closure $fail) {
19+
// Intentionally left empty.
20+
},
21+
]
1622
];
1723
}
1824
}

0 commit comments

Comments
 (0)