Add currency_id column to recurrings table
MODIFY
app/Models/Recurring.php
app/Models/Recurring.php
@@ -21,7 +21,8 @@ class Recurring extends Model
'last_used_on',
'tag_id',
'description',
- 'amount'
+ 'amount',
+ 'currency_id'
];
protected $dates = ['deleted_at'];

ADD
database/migrations/2020_06_30_204814_add_currency_id_column_to_recurrings_table.php
+<?php
+
+use App\Models\Recurring;
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddCurrencyIdColumnToRecurringsTable extends Migration
+{
+ public function up(): void
+ {
+ Schema::table('recurrings', function (Blueprint $table) {
+ $table->unsignedInteger('currency_id')->after('amount');
+ });
+
+ // Set "currency_id" for existing recurrings
+ foreach (Recurring::all() as $recurring) {
+ $recurring->fill([
+ 'currency_id' => $recurring->space->currency_id
+ ])->save();
+ }
+ }
+
+ public function down(): void
+ {
+ Schema::table('recurrings', function (Blueprint $table) {
+ $table->dropColumn('currency_id');
+ });
+ }
+}

Add currency_id column to recurrings table