Skip to content

Commit b683bdf

Browse files
committed
=Fixes a bug with the is-nullable field when using --table-exists option
1 parent c60d0f4 commit b683bdf

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# An awesome code generator for laravel framework - with client-side validation
22

3-
For full documentation and live demo please visit <a href="https://crestapps.com/laravel-code-generator/docs/1.1" target="_blank" title="Laravel Code Generator Documentation">CrestApps.com</a>
3+
For full documentation and live demo please visit <a href="https://crestapps.com/laravel-code-generator/docs/1.2" target="_blank" title="Laravel Code Generator Documentation">CrestApps.com</a>
44

55
## Introduction
66

@@ -71,9 +71,9 @@ php artisan vendor:publish --provider="CrestApps\CodeGenerator\CodeGeneratorServ
7171
* php artisan create:language [language-file-name]
7272
* php artisan create:fields-file [table-name]
7373

74-
> Full documentation available at [CrestApps.com](https://www.crestapps.com/laravel-code-generator/docs/1.1 "Laravel Code Generator Documentation").
74+
> Full documentation available at [CrestApps.com](https://www.crestapps.com/laravel-code-generator/docs/1.2 "Laravel Code Generator Documentation").
7575
76-
> Live demo is available at [CrestApps.com](https://www.crestapps.com/laravel-code-generator/demos/1.1 "Laravel Code Generator Live Demo").
76+
> Live demo is available at [CrestApps.com](https://www.crestapps.com/laravel-code-generator/demos/1.2 "Laravel Code Generator Live Demo").
7777
7878

7979
## License

src/DatabaseParsers/ParserBase.php

+23-2
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,22 @@ protected function setHtmlType(Field & $field, $type)
137137
return $this;
138138
}
139139

140+
/**
141+
* Set the required validation rule.
142+
*
143+
* @param CrestApps\CodeGenerator\Models\Field $field
144+
*
145+
* @return $this
146+
*/
147+
protected function setRequired(Field & $field)
148+
{
149+
if (!$field->isNullable) {
150+
$field->validationRules[] = 'required';
151+
}
152+
153+
return $this;
154+
}
155+
140156
/**
141157
* Set the data type for a giving field.
142158
*
@@ -153,6 +169,11 @@ protected function setDataType(Field & $field, $type)
153169
$field->dataType = $map[$type];
154170
}
155171

172+
if($field->dataType == 'boolean')
173+
{
174+
$field->validationRules[] = 'boolean';
175+
}
176+
156177
return $this;
157178
}
158179

@@ -167,8 +188,8 @@ protected function setDataType(Field & $field, $type)
167188
protected function setIsNullable(Field & $field, $nullable)
168189
{
169190
$field->isNullable = (strtoupper($nullable) == 'YES');
170-
171-
return $this;
191+
192+
return $this->setRequired($field);
172193
}
173194

174195
/**

src/Support/FieldOptimizer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ protected function optimizeStringField()
9999
*/
100100
protected function optimizeRequiredField()
101101
{
102-
if (!$this->parser->isRequired() || $this->parser->isNullable() || $this->parser->isConditionalRequired()) {
102+
if ($this->parser->isNullable() || !$this->parser->isRequired() || $this->parser->isConditionalRequired()) {
103103
$this->field->isNullable = true;
104104
}
105105

src/Support/ValidationParser.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ public function isConditionalRequired()
274274
* @return bool
275275
*/
276276
public function isNullable()
277-
{
277+
{
278278
if (is_null($this->nullable)) {
279279
$this->nullable = $this->isRuleExists('nullable');
280280
}

0 commit comments

Comments
 (0)