Skip to content

Commit 0189940

Browse files
committed
Fix: Datepicker field formatting when it is empty
1 parent 86a9a3c commit 0189940

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/Builders/ModelBuilder.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function build()
4444
$this->datetime = $cached['datetime'];
4545
$this->enum = $cached['enum'];
4646
$this->names();
47-
$template = (string) $this->loadTemplate();
47+
$template = (string)$this->loadTemplate();
4848
$template = $this->buildParts($template);
4949
$this->publish($template);
5050
}
@@ -133,7 +133,7 @@ private function buildFillables()
133133
}
134134
foreach ($this->fields as $key => $field) {
135135
// Check if there is no duplication for radio and checkbox
136-
if (!in_array($field->title, $used)) {
136+
if (! in_array($field->title, $used)) {
137137
if ($count > 1) {
138138
$fillables .= ' '; // Add formatting space to the model
139139
}
@@ -148,10 +148,12 @@ private function buildFillables()
148148
if ($count != 1) {
149149
if ($key != $count - 1) {
150150
$fillables .= ",\r\n";
151-
} else if ($key == $count - 1) {
152-
$fillables .= "\r\n ";
153151
} else {
154-
$fillables .= "\r\n";
152+
if ($key == $count - 1) {
153+
$fillables .= "\r\n ";
154+
} else {
155+
$fillables .= "\r\n";
156+
}
155157
}
156158
}
157159
}
@@ -170,7 +172,7 @@ private function buildRelationships()
170172
$used = [];
171173
$relationships = '';
172174
foreach ($this->fields as $key => $field) {
173-
if (!in_array($field->title, $used) && $field->type == 'relationship') {
175+
if (! in_array($field->title, $used) && $field->type == 'relationship') {
174176
$menu = $menus[$field->relationship_id];
175177
$relLine = '
176178
public function $RELATIONSHIP$()
@@ -242,7 +244,11 @@ private function datepickers()
242244
*/
243245
public function set' . $camel . 'Attribute($input)
244246
{
245-
$this->attributes[\'' . $field->title . '\'] = Carbon::createFromFormat(config(\'quickadmin.date_format\'), $input)->format(\'Y-m-d\');
247+
if($input != \'\') {
248+
$this->attributes[\'' . $field->title . '\'] = Carbon::createFromFormat(config(\'quickadmin.date_format\'), $input)->format(\'Y-m-d\');
249+
}else{
250+
$this->attributes[\'' . $field->title . '\'] = \'\';
251+
}
246252
}
247253
248254
/**
@@ -253,7 +259,11 @@ public function set' . $camel . 'Attribute($input)
253259
*/
254260
public function get' . $camel . 'Attribute($input)
255261
{
256-
return Carbon::createFromFormat(\'Y-m-d\', $input)->format(config(\'quickadmin.date_format\'));
262+
if($input != \'\') {
263+
return Carbon::createFromFormat(\'Y-m-d\', $input)->format(config(\'quickadmin.date_format\'));
264+
}else{
265+
return \'\';
266+
}
257267
}' . "\r\n\r\n";
258268
}
259269
}

0 commit comments

Comments
 (0)