From ae2f980135da1cb3c8c67df3e7538ca397641699 Mon Sep 17 00:00:00 2001 From: Kevin MacMartin Date: Mon, 3 Jul 2023 22:18:19 -0400 Subject: [PATCH] Only force unique columns to be unique when they aren't empty (otherwise, use required to ensure the column is empty) --- app/Http/Controllers/DashboardController.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php index 227c4e1..e49a7b1 100644 --- a/app/Http/Controllers/DashboardController.php +++ b/app/Http/Controllers/DashboardController.php @@ -218,11 +218,13 @@ class DashboardController extends Controller { return 'required:' . implode(',', $empty); } - // check to ensure unique columns are unique + // check to ensure unique columns are unique when they aren't empty $not_unique = []; foreach ($model_class::$dashboard_columns as $column) { - if ($request->has($column['name']) && array_key_exists('unique', $column) && $column['unique'] && $model_class::where($column['name'], $request[$column['name']])->where('id', '!=', $item->id)->exists()) { + $column_name = $column['name']; + + if ($request->has($column['name']) && $request->$column_name != '' && array_key_exists('unique', $column) && $column['unique'] && $model_class::where($column['name'], $request[$column['name']])->where('id', '!=', $item->id)->exists()) { if (array_key_exists('title', $column)) { array_push($not_unique, "'" . $column['title'] . "'"); } else {