Skip to content

Commit 26d7bad

Browse files
committed
Refactor to use Laravel validation for range validation
1 parent 307bac5 commit 26d7bad

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

packages/framework/src/Console/Commands/MakePublicationTypeCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ protected function captureFieldsDefinitions(): Collection
9090
if ($type < 10) {
9191
do {
9292
$fieldData['min'] = trim($this->askWithValidation('min', 'Min value (for strings, this refers to string length)', ['required', 'string'], 0));
93-
$fieldData['max'] = trim($this->askWithValidation('max', 'Max value (for strings, this refers to string length)', ['required', 'string'], 0));
93+
$fieldData['max'] = trim($this->askWithValidation('max', 'Max value (for strings, this refers to string length)', ['required', 'string', 'gt:'.(int)$fieldData['min']], 0));
9494
$lengthsValid = $this->validateLengths($fieldData['min'], $fieldData['max']);
9595
} while (! $lengthsValid);
9696
} else {

packages/framework/tests/Feature/Commands/MakePublicationTypeCommandTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,17 @@ public function test_command_creates_publication_type()
8686

8787
// TODO: Assert Blade templates were created?
8888
}
89+
90+
public function test_cannot_create_field_with_lower_max_than_min_value()
91+
{
92+
$this->artisan('make:publicationType test-publication')
93+
->expectsQuestion('Field name', 'foo')
94+
->expectsQuestion('Field type', 'foo')
95+
->expectsQuestion('Min value (for strings, this refers to string length)', 10)
96+
->expectsQuestion('Max value (for strings, this refers to string length)', 5)
97+
->expectsQuestion('Min value (for strings, this refers to string length)', 5)
98+
->expectsQuestion('Max value (for strings, this refers to string length)', 10)
99+
100+
->assertSuccessful();
101+
}
89102
}

0 commit comments

Comments
 (0)