Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require is not null #532

Merged
merged 5 commits into from Mar 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Common/GeneratorField.php
Expand Up @@ -27,6 +27,7 @@ class GeneratorField
public $isPrimary = false;
public $inForm = true;
public $inIndex = true;
public $isNotNull = false;

public function parseDBType($dbInput)
{
Expand Down
6 changes: 6 additions & 0 deletions src/Generators/ModelGenerator.php
Expand Up @@ -230,9 +230,15 @@ private function fillTimestamps($templateData)

private function generateRules()
{
$dont_require_fields = config('infyom.laravel_generator.options.hidden_fields', [])
+ config('infyom.laravel_generator.options.excluded_fields', []);

$rules = [];

foreach ($this->commandData->fields as $field) {
if ($field->isNotNull && empty($field->validations) && !in_array($field->name, $dont_require_fields)) {
$field->validations = 'required';
}
if (!empty($field->validations)) {
$rule = "'".$field->name."' => '".$field->validations."'";
$rules[] = $rule;
Expand Down
3 changes: 3 additions & 0 deletions src/Generators/Scaffold/ViewGenerator.php
Expand Up @@ -302,6 +302,9 @@ private function generateFields()
$fieldTemplate = HTMLFieldGenerator::generateHTML($field, $this->templateType);

if (!empty($fieldTemplate)) {
if ($field->isNotNull) {
$fieldTemplate = str_replace('$FIELD_NAME_TITLE$', '$FIELD_NAME_TITLE$'.($field->isNotNull ? ' <span class="required">*</span>' : ''), $fieldTemplate);
}
$fieldTemplate = fill_template_with_field_data(
$this->commandData->dynamicVars,
$this->commandData->fieldNamesMapping,
Expand Down
1 change: 1 addition & 0 deletions src/Utils/TableFieldsGenerator.php
Expand Up @@ -128,6 +128,7 @@ public function prepareFieldsFromTable()
$field->inForm = false;
$field->inIndex = false;
}
$field->isNotNull = (bool) $column->getNotNull();

$this->fields[] = $field;
}
Expand Down