Add ability to delete imports
MODIFY
app/Http/Controllers/ImportController.php
app/Http/Controllers/ImportController.php
@@ -140,4 +140,12 @@ class ImportController extends Controller {
return redirect()->route('imports.index');
}
+
+ public function destroy(Request $request, Import $import) {
+ if (!$import->spendings->count()) {
+ $import->delete();
+ }
+
+ return redirect()->route('imports.index');
+ }
}

MODIFY
app/Import.php
app/Import.php
@@ -17,4 +17,9 @@ class Import extends Model {
'column_description',
'column_amount'
];
+
+ // Relations
+ public function spendings() {
+ return $this->hasMany(Spending::class);
+ }
}

MODIFY
resources/views/imports/index.blade.php
resources/views/imports/index.blade.php
<a href="/imports/{{ $import->id }}/{{ $import->status == 0 ? 'prepare' : 'complete' }}">Next</a>
@endif
</div>
+ <div class="row__column row__column--compact ml-2 text-right">
+ @if ($import->spendings->count())
+ <i class="far fa-trash-alt"></i>
+ @else
+ <form method="POST" action="/imports/{{ $import->id }}">
+ {{ method_field('DELETE') }}
+ {{ csrf_field() }}
+ <button class="button link">
+ <i class="far fa-trash-alt"></i>
+ </button>
+ </form>
+ @endif
+ </div>
</div>
@endforeach
@else

MODIFY
routes/web.php
routes/web.php
@@ -53,6 +53,7 @@ Route::group(['middleware' => ['auth']], function () {
Route::post('/imports/{import}/prepare', 'ImportController@postPrepare');
Route::get('/imports/{import}/complete', 'ImportController@getComplete')->name('complete');
Route::post('/imports/{import}/complete', 'ImportController@postComplete');
+ Route::delete('/imports/{import}', 'ImportController@destroy');
});
Route::get('/settings', 'SettingsController@index')->name('settings');

Add ability to delete imports