Handle day updates during Goal edit

This commit is contained in:
Christopher C. Wells 2021-05-15 21:25:01 -07:00 committed by Christopher Charbonneau Wells
parent 2ba441dd08
commit 86b61dba30
2 changed files with 8 additions and 5 deletions

View File

@ -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');
}
/**

View File

@ -22,12 +22,12 @@
</div>
<div class="flex flex-col space-y-4 md:flex-row md:space-x-4 md:space-y-0">
<!-- Days of the week -->
<fieldset class="flex-auto">
<fieldset>
<legend class="block font-medium text-sm text-gray-700">Days of the week</legend>
<div class="inline-flex justify-between divide-x border rounded-md shadow-sm border-gray-300">
<div class="flex flex-col justify-content divide-x border rounded-md shadow-sm border-gray-300 md:inline-flex md:flex-row">
@foreach(\App\Models\Goal::days() as $day)
<x-inputs.label class="inline-flex items-center p-2">
<x-inputs.input type="checkbox" name="days[]" :value="$day['value']" />
<x-inputs.label class="inline-flex justify-center p-2">
<x-inputs.input type="checkbox" name="days[]" :value="$day['value']" :checked="($goal->days & $day['value']) != 0" />
<span class="ml-2">{{ \Illuminate\Support\Str::ucfirst($day['label']) }}</span>
</x-inputs.label>
@endforeach