Skip to content

Commit 69a3972

Browse files
committed
Bugfix'es: #45 and #52 plus bug with radio input values fix
1 parent 3afbfca commit 69a3972

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"email": "[email protected]"
1313
}
1414
],
15-
"version": "1.1.5",
15+
"version": "1.1.6",
1616
"require": {
1717
"laravelcollective/html": "5.2.*",
1818
"intervention/image": "^2.3",

src/Builders/ModelBuilder.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,11 @@ private function datetimepickers()
283283
*/
284284
public function set' . $camel . 'Attribute($input)
285285
{
286-
$this->attributes[\'' . $field->title . '\'] = Carbon::createFromFormat(config(\'quickadmin.date_format\') . \' \' . config(\'quickadmin.time_format\'), $input)->format(\'Y-m-d H:i:s\');
286+
if($input != \'\') {
287+
$this->attributes[\'' . $field->title . '\'] = Carbon::createFromFormat(config(\'quickadmin.date_format\') . \' \' . config(\'quickadmin.time_format\'), $input)->format(\'Y-m-d H:i:s\');
288+
}else{
289+
$this->attributes[\'' . $field->title . '\'] = \'\';
290+
}
287291
}
288292
289293
/**
@@ -294,7 +298,11 @@ public function set' . $camel . 'Attribute($input)
294298
*/
295299
public function get' . $camel . 'Attribute($input)
296300
{
297-
return Carbon::createFromFormat(\'Y-m-d H:i:s\', $input)->format(config(\'quickadmin.date_format\') . \' \' .config(\'quickadmin.time_format\'));
301+
if($input != \'0000-00-00\') {
302+
return Carbon::createFromFormat(\'Y-m-d H:i:s\', $input)->format(config(\'quickadmin.date_format\') . \' \' .config(\'quickadmin.time_format\'));
303+
}else{
304+
return \'\';
305+
}
298306
}' . "\r\n\r\n";
299307
}
300308
}

src/Builders/ViewsBuilder.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function build()
4242
$this->fields = $cached['fields'];
4343
$this->files = $cached['files'];
4444
$this->names();
45-
$template = (array) $this->loadTemplate();
45+
$template = (array)$this->loadTemplate();
4646
$template = $this->buildParts($template);
4747
$this->publish($template);
4848
}
@@ -56,7 +56,7 @@ public function buildCustom($name)
5656
2 => ''
5757
];
5858
$this->names();
59-
$template = (array) $this->loadTemplate();
59+
$template = (array)$this->loadTemplate();
6060
$this->publishCustom($template);
6161

6262
}
@@ -141,7 +141,7 @@ private function buildTable()
141141
foreach ($this->fields as $field) {
142142
// Check if there is no duplication for radio and checkbox.
143143
// Password fields are excluded from the table too.
144-
if (!in_array($field->title, $used)
144+
if (! in_array($field->title, $used)
145145
&& $field->type != 'password'
146146
&& $field->type != 'textarea'
147147
&& $field->show == 1
@@ -173,12 +173,17 @@ private function buildEditForm()
173173
foreach ($this->fields as $field) {
174174
$title = $field->label;
175175
$label = $field->title;
176-
if (in_array($field->validation, $this->starred) && $field->type != 'password' && $field->type != 'file' && $field->type != 'photo') {
176+
if (in_array($field->validation,
177+
$this->starred) && $field->type != 'password' && $field->type != 'file' && $field->type != 'photo'
178+
) {
177179
$title .= '*';
178180
}
179181
if ($field->type == 'relationship') {
180182
$label = $field->relationship_name . '_id';
181183
}
184+
if ($field->type == 'checkbox') {
185+
$field->default = '$' . $this->model . '->' . $label . ' == 1';
186+
}
182187
$temp = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'Templates' . DIRECTORY_SEPARATOR . 'fields' . DIRECTORY_SEPARATOR . $field->type);
183188
$temp = str_replace([
184189
'old(\'$LABEL$\')',
@@ -195,7 +200,9 @@ private function buildEditForm()
195200
'old(\'$LABEL$\',$' . $this->resource . '->' . $label . ')',
196201
$label,
197202
$title,
198-
$field->value != '' ? ', "' . $field->value . '"' : '',
203+
$field->type != 'radio' ?
204+
$field->value != '' ? ', "' . $field->value . '"' : ''
205+
: "'$field->value'",
199206
$field->default,
200207
'$' . $field->relationship_name,
201208
$field->texteditor == 1 ? ' ckeditor' : '',
@@ -237,7 +244,9 @@ private function buildCreateForm()
237244
], [
238245
$key,
239246
$title,
240-
$field->value != '' ? ', ' . $field->value : '',
247+
$field->type != 'radio' ?
248+
$field->value != '' ? ', ' . $field->value : ''
249+
: "'$field->value'",
241250
$field->default,
242251
'$' . $field->relationship_name,
243252
$field->texteditor == 1 ? ' ckeditor' : '',
@@ -283,7 +292,7 @@ private function helper($value)
283292
*/
284293
private function publish($template)
285294
{
286-
if (!file_exists(base_path('resources' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'admin' . DIRECTORY_SEPARATOR . $this->path))) {
295+
if (! file_exists(base_path('resources' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'admin' . DIRECTORY_SEPARATOR . $this->path))) {
287296
mkdir(base_path('resources' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'admin' . DIRECTORY_SEPARATOR . $this->path));
288297
chmod(base_path('resources' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'admin'), 0777);
289298
}
@@ -297,7 +306,7 @@ private function publish($template)
297306

298307
private function publishCustom($template)
299308
{
300-
if (!file_exists(base_path('resources' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'admin' . DIRECTORY_SEPARATOR . $this->path))) {
309+
if (! file_exists(base_path('resources' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'admin' . DIRECTORY_SEPARATOR . $this->path))) {
301310
mkdir(base_path('resources' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'admin' . DIRECTORY_SEPARATOR . $this->path));
302311
chmod(base_path('resources' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'admin'), 0777);
303312
}

0 commit comments

Comments
 (0)