Support editing of transaction's tag
MODIFY
app/Http/Controllers/SpendingController.php
app/Http/Controllers/SpendingController.php
@@ -40,7 +40,9 @@ class SpendingController extends Controller {
public function edit(Spending $spending) {
$this->authorize('edit', $spending);
- return view('spendings.edit', compact('spending'));
+ $tags = session('space')->tags()->orderBy('created_at', 'DESC')->get();
+
+ return view('spendings.edit', compact('tags', 'spending'));
}
public function update(Request $request, Spending $spending) {
@@ -48,12 +50,14 @@ class SpendingController extends Controller {
// TODO MOVE TO CENTRAL PLACE FOR REUSABILITY
$request->validate([
+ 'tag_id' => 'nullable|exists:tags,id', // TODO CHECK IF TAG BELONGS TO USER
'date' => 'required|date|date_format:Y-m-d',
'description' => 'required|max:255',
'amount' => 'required|regex:/^\d*(\.\d{2})?$/'
]);
$spending->fill([
+ 'tag_id' => $request->input('tag_id'),
'happened_on' => $request->input('date'),
'description' => $request->input('description'),
'amount' => (int) ($request->input('amount') * 100)

MODIFY
resources/views/spendings/edit.blade.php
resources/views/spendings/edit.blade.php
{{ method_field('PATCH') }}
{{ csrf_field() }}
<div class="box__section">
+ <div class="input input--small">
+ <label>{{ __('models.tag') }}</label>
+ <select name="tag_id">
+ <option value="">-</option>
+ @foreach ($tags as $tag)
+ <option value="{{ $tag->id }}" {{ $tag->id === $spending->tag_id ? 'selected' : '' }}>{{ $tag->name }}</option>
+ @endforeach
+ </select>
+ @include('partials.validation_error', ['payload' => 'tag_id'])
+ </div>
<div class="input input--small">
<label>{{ __('fields.date') }}</label>
<DatePicker start-date="{{ $spending->happened_on }}"></DatePicker>

Support editing of transaction's tag