Check that the field is valid before checking to see count()

This mostly affects the demo, since the seeder updates info often

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2021-04-20 15:10:28 -07:00
parent e286ff0be3
commit c17eaaad69

View file

@ -151,11 +151,11 @@ class CustomFieldsController extends Controller
*/
public function destroy($field_id)
{
$field = CustomField::find($field_id);
if ($field = CustomField::find($field_id)) {
$this->authorize('delete', $field);
if ($field->fieldset->count()>0) {
if (($field->fieldset) && ($field->fieldset->count() > 0)) {
return redirect()->back()->withErrors(['message' => "Field is in-use"]);
}
$field->delete();
@ -163,6 +163,9 @@ class CustomFieldsController extends Controller
->with("success", trans('admin/custom_fields/message.field.delete.success'));
}
return redirect()->back()->withErrors(['message' => "Field does not exist"]);
}
/**
* Return a view to edit a custom field