Skip to content

Commit b78e610

Browse files
authored
Merge pull request #10480 from snipe/fixes/check_for_valid_custom_field
Fixed format property on invalid custom field object when trying to edit a field that doesn't exist
2 parents 7a1ab12 + 884b6b0 commit b78e610

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

app/Http/Controllers/CustomFieldsController.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -178,20 +178,25 @@ public function destroy($field_id)
178178
*/
179179
public function edit($id)
180180
{
181-
$field = CustomField::find($id);
181+
if ($field = CustomField::find($id)) {
182182

183-
$this->authorize('update', $field);
183+
$this->authorize('update', $field);
184184

185-
$customFormat = '';
186-
if((stripos($field->format, 'regex') === 0) && ($field->format !== CustomField::PREDEFINED_FORMATS['MAC'])) {
187-
$customFormat = $field->format;
188-
}
185+
$customFormat = '';
186+
if((stripos($field->format, 'regex') === 0) && ($field->format !== CustomField::PREDEFINED_FORMATS['MAC'])) {
187+
$customFormat = $field->format;
188+
}
189189

190-
return view("custom_fields.fields.edit",[
191-
'field' => $field,
192-
'customFormat' => $customFormat,
193-
'predefinedFormats' => Helper::predefined_formats()
194-
]);
190+
return view("custom_fields.fields.edit",[
191+
'field' => $field,
192+
'customFormat' => $customFormat,
193+
'predefinedFormats' => Helper::predefined_formats()
194+
]);
195+
}
196+
197+
return redirect()->route("fields.index")
198+
->with("error", trans('admin/custom_fields/message.field.invalid'));
199+
195200
}
196201

197202

0 commit comments

Comments
 (0)