Skip to content

Commit

Permalink
fix set nullable datatype datetime,date,time
Browse files Browse the repository at this point in the history
  • Loading branch information
miftahurrahmi committed Nov 21, 2023
1 parent 2f8b50d commit f273c3f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 23 deletions.
33 changes: 22 additions & 11 deletions src/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,31 @@ public function getContentByType($data_type, $data_row, $value)
$return_value = $value;
break;
case 'time':
$z_removed = explode('.', $value)[0];
$time = explode('T', $z_removed)[1];
$return_value = $time;
if ($value == null){
$return_value = $value;
}else{
$z_removed = explode('.', $value)[0];
$time = explode('T', $z_removed)[1];
$return_value = $time;
}
break;
case 'date':
$z_removed = explode('.', $value)[0];
$date = explode('T', $z_removed)[0];
$return_value = $date;
if($value == null){
$return_value = $value;
}else{
$z_removed = explode('.', $value)[0];
$date = explode('T', $z_removed)[0];
$return_value = $date;
}
break;
case 'datetime':
$z_removed = explode('.', $value)[0];
$date_time = str_replace('T', ' ', $z_removed);
$return_value = $date_time;
if($value == null){
$return_value = $value;
}else{
$z_removed = explode('.', $value)[0];
$date_time = str_replace('T', ' ', $z_removed);
$return_value = $date_time;
}
break;
case 'select':
$return_value = $value;
Expand Down Expand Up @@ -373,7 +385,6 @@ public function insertData($data, $data_type)
}
}
}

$id = DB::table($data_type->name)->insertGetId($new_data);
$model = DB::table($data_type->name)->where('id', $id)->first();
foreach ($data as $key => $value) {
Expand Down Expand Up @@ -567,7 +578,7 @@ public function updateData($data, $data_type)
}

if (in_array($data_row->type, [
'number',
'number','datetime','date','time'
])) {
$new_data[$key] = $this->getContentByType($data_type, $data_row, $value) !== null ? $this->getContentByType($data_type, $data_row, $value) : null;
} else {
Expand Down
32 changes: 20 additions & 12 deletions src/resources/js/pages/crud-generated/edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
<template v-if="dataRow.edit && dataRow.type !== 'hidden'">
<!-- <input type="text" v-model="dataRow.value"> -->
<!-- <vs-input type="text" v-model="dataRow.value"></vs-input> -->

<badaso-text
v-if="dataRow.type == 'text'"
:label="dataRow.displayName"
Expand Down Expand Up @@ -503,16 +502,7 @@ export default {
data.value = parseInt(
this.record[this.$caseConvert.stringSnakeToCamel(data.field)]
);
} else if (data.type == "datetime" || data.type == "date") {
var dateValue = this.record[
this.$caseConvert.stringSnakeToCamel(data.field)
]
? this.record[
this.$caseConvert.stringSnakeToCamel(data.field)
].replace(" ", "T")
: null;
data.value = new Date(dateValue);
} else if (data.value == undefined && data.type == "hidden") {
}else if (data.value == undefined && data.type == "hidden") {
data.value = data.details.value ? data.details.value : "";
} else if (
data.type == "text" ||
Expand All @@ -526,7 +516,25 @@ export default {
]
? this.record[this.$caseConvert.stringSnakeToCamel(data.field)]
: "";
} else if (
}
else if(data.type == "datetime"){
data.value = this.record[
this.$caseConvert.stringSnakeToCamel(data.field)
]
? this.record[
this.$caseConvert.stringSnakeToCamel(data.field)
].replace(" ", "T")
: null;
}else if(data.type == "date"){
var val = this.record[
this.$caseConvert.stringSnakeToCamel(data.field)
]
? this.record[
this.$caseConvert.stringSnakeToCamel(data.field)
].replace(" ", "T")
: null;
data.value = val !== null ? new Date(val) : val;
}else if(
data.type == "relation" &&
data.relation.relationType == "belongs_to_many"
) {
Expand Down

0 comments on commit f273c3f

Please sign in to comment.