Create migration for adding import_id column to spendings table
MODIFY
app/Spending.php
app/Spending.php
@@ -22,6 +22,10 @@ class Spending extends Model {
}
// Relations
+ public function import() {
+ return $this->belongsTo(Import::class);
+ }
+
public function recurring() {
return $this->belongsTo(Recurring::class);
}

ADD
database/migrations/2018_10_14_132003_add_import_id_column_to_spendings_table.php
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AddImportIdColumnToSpendingsTable extends Migration {
+ public function up() {
+ Schema::table('spendings', function (Blueprint $table) {
+ $table->unsignedInteger('import_id')->nullable()->after('space_id');
+
+ // FK
+ $table->foreign('import_id')->references('id')->on('imports');
+ });
+ }
+
+ public function down() {
+ Schema::table('spendings', function (Blueprint $table) {
+ // FK
+ $table->dropForeign('spendings_import_id_foreign');
+
+ $table->dropColumn('import_id');
+ });
+ }
+}

Create migration for adding import_id column to spendings table