From 86b61dba30cad54d02994ee3ee18e0a787d949ad Mon Sep 17 00:00:00 2001 From: "Christopher C. Wells" Date: Sat, 15 May 2021 21:25:01 -0700 Subject: [PATCH] Handle day updates during Goal edit --- app/Http/Controllers/GoalController.php | 5 ++++- resources/views/goals/edit.blade.php | 8 ++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/GoalController.php b/app/Http/Controllers/GoalController.php index a714a4e..407f361 100644 --- a/app/Http/Controllers/GoalController.php +++ b/app/Http/Controllers/GoalController.php @@ -62,10 +62,13 @@ class GoalController extends Controller if (isset($attributes['days'])) { $attributes['days'] = array_sum($attributes['days']); } + else if (!empty($goal->days)) { + $attributes['days'] = null; + } $goal->fill($attributes)->user()->associate(Auth::user()); $goal->save(); session()->flash('message', "Goal updated!"); - return redirect()->route('goals.show', $goal); + return redirect()->route('goals.index'); } /** diff --git a/resources/views/goals/edit.blade.php b/resources/views/goals/edit.blade.php index b9a1f16..52f5832 100644 --- a/resources/views/goals/edit.blade.php +++ b/resources/views/goals/edit.blade.php @@ -22,12 +22,12 @@
-
+
Days of the week -
+
@foreach(\App\Models\Goal::days() as $day) - - + + {{ \Illuminate\Support\Str::ucfirst($day['label']) }} @endforeach