Allow usage of tags while importing
MODIFY
app/Http/Controllers/ImportController.php
app/Http/Controllers/ImportController.php
@@ -77,6 +77,8 @@ class ImportController extends Controller {
public function getComplete(Import $import) {
$this->authorize('modify', $import);
+ $tags = session('space')->tags;
+
$file = fopen(storage_path('app/imports/' . $import->file), 'r');
$heading = true;
@@ -94,7 +96,7 @@ class ImportController extends Controller {
}
}
- return view('imports.complete', compact('rows'));
+ return view('imports.complete', compact('tags', 'rows'));
}
public function postComplete(Request $request, Import $import) {
@@ -111,6 +113,7 @@ class ImportController extends Controller {
foreach ($request->input('rows') as $i => $row) {
if (isset($row['import']) && $row['import'] == 'on') {
$validator = Validator::make($row, [
+ 'tag_id' => 'nullable|exists:tags,id', // TODO CHECK IF TAG BELONGS TO USER
'happened_on' => 'date|date_format:' . $date_format,
'description' => 'max:255',
'amount' => 'regex:/^\d*([\,\.]\d{2})?$/'
@@ -138,6 +141,7 @@ class ImportController extends Controller {
Spending::create([
'space_id' => session('space')->id,
'import_id' => $import->id,
+ 'tag_id' => $row['tag_id'],
'happened_on' => $row['happened_on'],
'description' => $row['description'],
'amount' => (int) ($amount * 100)

MODIFY
app/Spending.php
app/Spending.php
@@ -13,6 +13,7 @@ class Spending extends Model {
protected $fillable = [
'space_id',
'import_id',
+ 'tag_id',
'happened_on',
'description',
'amount'

MODIFY
resources/views/imports/complete.blade.php
resources/views/imports/complete.blade.php
<div class="box__section box__section--header">
<div class="row row--gutter">
<div class="row__column row__column--compact" style="width: 100px;">Import</div>
+ <div class="row__column">{{ __('models.tag') }}</div>
<div class="row__column">{{ __('fields.date') }}</div>
<div class="row__column row__column--triple">{{ __('fields.description') }}</div>
<div class="row__column">{{ __('fields.amount') }}</div>
<div class="row row--gutter">
<div class="row__column row__column--compact row__column--middle" style="width: 100px;">
<input type="checkbox" name="rows[{{ $index }}][import]" {{ old('rows.' . $index . '.import') == 'on' ? 'checked' : '' }} /></div>
+ <div class="row__column">
+ <select name="rows[{{ $index }}][tag_id]">
+ <option value="">-</option>
+ @foreach ($tags as $tag)
+ <option value="{{ $tag->id }}">{{ $tag->name }}</option>
+ @endforeach
+ </select>
+ @include('partials.validation_error', ['payload' => 'rows.' . $index . '.tag_id'])
+ </div>
<div class="row__column">
<input type="text" name="rows[{{ $index }}][happened_on]" value="{{ old('rows.' . $index . '.happened_on') ? old('rows.' . $index . '.happened_on') : $row['happened_on'] }}" />
@include('partials.validation_error', ['payload' => 'rows.' . $index . '.happened_on'])

Allow usage of tags while importing