From 3a3ddd09d3b3b51383a253c09ed5a8e59ad9e6e9 Mon Sep 17 00:00:00 2001 From: Kevin MacMartin Date: Tue, 1 May 2018 20:14:00 -0400 Subject: [PATCH] Consider the reorder column if present when adding and deleting new rows --- app/Http/Controllers/DashboardController.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php index 678be9d..c1544cd 100644 --- a/app/Http/Controllers/DashboardController.php +++ b/app/Http/Controllers/DashboardController.php @@ -167,6 +167,10 @@ class DashboardController extends Controller { if ($model_class != null) { if ($request['id'] == 'new') { $item = new $model_class; + + if ($model_class::$dashboard_reorder) { + $item->{$model_class::$dashboard_sort_column} = $model_class::count(); + } } else { $item = $model_class::find($request['id']); @@ -297,6 +301,14 @@ class DashboardController extends Controller { } } + // update the order of the remaining rows if $dashboard_reorder is true + if ($model_class::$dashboard_reorder) { + foreach ($model_class::getDashboardData() as $index => $item) { + $item->{$model_class::$dashboard_sort_column} = $index; + $item->save(); + } + } + // Return a success return 'success'; } else {