dropForeign(['site_id']); $table->datetime('created_at')->nullable()->after('id'); $table->datetime('updated_at')->nullable()->after('created_at'); $table->boolean('active')->nullable()->after('updated_at'); $table->date('paid_at')->nullable()->after('payment_date'); $table->foreign(['account_id','site_id'])->references(['id','site_id'])->on('accounts'); $table->foreign(['source_id','site_id'])->references(['id','site_id'])->on('users'); }); // Convert out dates foreach (\App\Models\Payment::withoutGlobalScope(\App\Models\Scopes\SiteScope::class)->cursor() as $o) { if ($o->date_orig) $o->created_at = \Carbon\Carbon::createFromTimestamp($o->date_orig); if ($o->date_last) $o->updated_at = \Carbon\Carbon::createFromTimestamp($o->date_last); if ($o->payment_date) $o->paid_at = \Carbon\Carbon::createFromTimestamp($o->payment_date); $o->save(); } Schema::table('payments', function (Blueprint $table) { $table->dropColumn(['date_orig','date_last','payment_date']); }); DB::statement('ALTER TABLE payment_items MODIFY payment_id int unsigned NOT NULL'); DB::statement('ALTER TABLE payment_items MODIFY invoice_id int unsigned DEFAULT NULL'); DB::statement('ALTER TABLE payment_items RENAME COLUMN alloc_amt TO amount'); Schema::table('payment_items', function (Blueprint $table) { $table->dropForeign(['site_id']); $table->boolean('active')->nullable()->after('site_id'); $table->dropColumn(['date_orig','date_last']); $table->foreign(['payment_id','site_id'])->references(['id','site_id'])->on('payments'); }); DB::statement('UPDATE payment_items SET active=1'); } /** * Reverse the migrations. * * @return void */ public function down() { abort(500,'Cant go back'); } };