Skip to content

Commit f1d8d18

Browse files
committed
Relationship select now can be empty (added checking if the relationship is set on list page)
Every optional field should be generated as nullable now
1 parent 3e7852c commit f1d8d18

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"email": "[email protected]"
1212
}
1313
],
14-
"version": "0.4.4",
14+
"version": "0.4.5",
1515
"require": {
1616
"illuminate/html": "5.0.*@dev",
1717
"intervention/image": "^2.3",

src/Builders/MigrationBuilder.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ private function buildFields()
106106
}
107107
$migrationLine = str_replace('$VALUES$', $values, $migrationLine);
108108
}
109-
$fields .= '$table->' . $migrationLine . ";\r\n";
109+
$fields .= '$table->' . $migrationLine;
110+
if (in_array($field->validation, FieldsDescriber::nullables())) {
111+
$fields .= '->nullable()';
112+
}
113+
$fields .= ";\r\n";
110114
if ($field->type == 'relationship') {
111115
$used[$field->relationship_name] = $field->relationship_name;
112116
} else {

src/Builders/ViewsBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ private function buildTable()
149149
$headings .= "<th>$field->label</th>\r\n";
150150
// Format our table column by field type
151151
if ($field->type == 'relationship') {
152-
$columns .= '<td>{{ $row->' . $field->relationship_name . '->' . $field->relationship_field . " }}</td>\r\n";
152+
$columns .= '<td>{{ isset($row->' . $field->relationship_name . '->' . $field->relationship_field . ') ? $row->' . $field->relationship_name . '->' . $field->relationship_field . " : '' }}</td>\r\n";
153153
$used[$field->relationship_field] = $field->relationship_field;
154154
} elseif ($field->type == 'photo') {
155155
$columns .= '<td>@if($row->' . $field->title . ' != \'\')<img src="{{ asset(\'uploads/thumb\') . \'/\'. $row->' . $field->title . " }}\">@endif</td>\r\n";

src/Fields/FieldsDescriber.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ public static function validation()
3939
];
4040
}
4141

42+
/**
43+
* Set fields to be nullable by default if validation is not in this array
44+
* @return array
45+
*/
46+
public static function nullables()
47+
{
48+
return [
49+
'optional',
50+
];
51+
}
52+
4253
/**
4354
* Default QuickAdmin field types for migration
4455
* @return array

0 commit comments

Comments
 (0)