Skip to content

Commit

Permalink
File upload field bugfix on edit page. Before this patch file was alw…
Browse files Browse the repository at this point in the history
…ays required when editing CRUD.
  • Loading branch information
ModestasV committed Dec 23, 2015
1 parent f1d8d18 commit 4a9fdbf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 16 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"email": "[email protected]"
}
],
"version": "0.4.5",
"version": "0.4.6",
"require": {
"illuminate/html": "5.0.*@dev",
"intervention/image": "^2.3",
Expand Down
46 changes: 32 additions & 14 deletions src/Builders/RequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,38 @@ private function buildRules($type)
break;
}
} elseif ($field->type == 'file' || $field->type == 'photo') {
switch ($field->validation) {
case 'required':
$rules .= "'$field->title' => 'max:$field->size|$field->validation', \r\n ";
break;
case 'required|unique':
$camelName = Str::camel($this->name);
// Insert table names
$tableName = strtolower($camelName);
$rules .= "'$field->title' => 'max:$field->size|$field->validation:$tableName,$field->title,'." . '$this->' . $this->request . ", \r\n ";
break;
default:
// We got a file field which has a bit different validation
$rules .= "'$field->title' => 'max:$field->size', \r\n ";
break;
if ($type == 0) {
switch ($field->validation) {
case 'required':
$rules .= "'$field->title' => 'max:$field->size|$field->validation', \r\n ";
break;
case 'required|unique':
$camelName = Str::camel($this->name);
// Insert table names
$tableName = strtolower($camelName);
$rules .= "'$field->title' => 'max:$field->size|$field->validation:$tableName,$field->title,'." . '$this->' . $this->request . ", \r\n ";
break;
default:
// We got a file field which has a bit different validation
$rules .= "'$field->title' => 'max:$field->size', \r\n ";
break;
}
} else {
switch ($field->validation) {
case 'required':
$rules .= "'$field->title' => 'max:$field->size', \r\n ";
break;
case 'required|unique':
$camelName = Str::camel($this->name);
// Insert table names
$tableName = strtolower($camelName);
$rules .= "'$field->title' => 'max:$field->size|$field->validation:$tableName,$field->title,'." . '$this->' . $this->request . ", \r\n ";
break;
default:
// We got a file field which has a bit different validation
$rules .= "'$field->title' => 'max:$field->size', \r\n ";
break;
}
}

} elseif ($field->type == 'money') {
Expand Down
2 changes: 1 addition & 1 deletion src/Builders/ViewsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private function buildEditForm()
foreach ($this->fields as $field) {
$title = $field->label;
$label = $field->title;
if (in_array($field->validation, $this->starred) && $field->type != 'password') {
if (in_array($field->validation, $this->starred) && $field->type != 'password' && $field->type != 'file' && $field->type != 'photo') {
$title .= '*';
}
if ($field->type == 'relationship') {
Expand Down

0 comments on commit 4a9fdbf

Please sign in to comment.