Validate the creation of new spendings
MODIFY
app/Http/Controllers/SpendingsController.php
app/Http/Controllers/SpendingsController.php
@@ -29,6 +29,13 @@ class SpendingsController extends Controller {
}
public function store(Request $request) {
+ $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{1,2})?$/'
+ ]);
+
$spending = new Spending;
$spending->user_id = Auth::user()->id;

MODIFY
resources/views/spendings/create.blade.php
resources/views/spendings/create.blade.php
<option value="{{ $tag->id }}">{{ $tag->name }}</option>
@endforeach
</select>
+ @include('partials.validation_error', ['payload' => 'tag_id'])
</div>
<div class="input input--small">
<label>Date</label>
<DatePicker></DatePicker>
+ @include('partials.validation_error', ['payload' => 'date'])
</div>
<div class="input input--small">
<label>Description</label>
<input type="text" name="description" />
+ @include('partials.validation_error', ['payload' => 'description'])
</div>
<div class="input input--small">
<label>Amount</label>
<input type="text" name="amount" />
+ @include('partials.validation_error', ['payload' => 'amount'])
</div>
<button>@lang('actions.create')</button>
</form>

Validate the creation of new spendings