Add iso column to currencies table
MODIFY
app/Models/Currency.php
app/Models/Currency.php
@@ -7,4 +7,8 @@ use Illuminate\Database\Eloquent\Model;
class Currency extends Model
{
public $timestamps = false;
+
+ protected $fillable = [
+ 'iso'
+ ];
}

ADD
database/migrations/2020_07_01_230418_add_iso_column_to_currencies_table.php
+<?php
+
+use App\Models\Currency;
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddIsoColumnToCurrenciesTable extends Migration
+{
+ public function up(): void
+ {
+ Schema::table('currencies', function (Blueprint $table) {
+ $table->string('iso')->after('symbol');
+ });
+
+ foreach (Currency::all() as $currency) {
+ $iso = $currency->symbol;
+
+ if (strlen($currency->symbol) !== 3) {
+ switch ($currency->symbol) {
+ case '&euro;';
+ $iso = 'EUR';
+ break;
+
+ case '&dollar;';
+ $iso = 'USD';
+ break;
+
+ case '&pound;';
+ $iso = 'GBP';
+ break;
+ }
+ }
+
+ $currency->fill(['iso' => $iso])->save();
+ }
+ }
+
+ public function down(): void
+ {
+ Schema::table('currencies', function (Blueprint $table) {
+ $table->dropColumn('iso');
+ });
+ }
+}

Add iso column to currencies table