diff --git a/app/Console/Commands/Files/ImportAllianceMoons.php b/app/Console/Commands/Files/ImportAllianceMoons.php index e486e416e..9a083fef9 100644 --- a/app/Console/Commands/Files/ImportAllianceMoons.php +++ b/app/Console/Commands/Files/ImportAllianceMoons.php @@ -62,6 +62,9 @@ class ImportAllianceMoons extends Command //Create the collection of lines for the input file. $moons = new Collection; + AllianceMoonOre::truncate(); + AllianceMoon::truncate(); + //Create the file handler $data = Storage::get('public/alliance_moons.txt'); //Split the string into separate arrays based on the line @@ -84,19 +87,19 @@ class ImportAllianceMoons extends Command //Start working our way through all of the moons //and saving the data to the database foreach($moons as $moon) { - //Declare variables for each instance of the foreach loop - $moonId = null; - $moonName = null; - $oreId = null; - $oreName = null; - $oreQuantity = null; - $systemId = null; - $systemname = null; - - var_dump($moon); - + //If the first array is null then we are dealing with an ore + if($moon[0] == null) { + //Save a new entry into the database + $ore = new AllianceMoonOre; + $ore->moon_id = $moon[6]; + $ore->moon_name = null; + $ore->ore_type_id = $moon[3]; + $ore->ore_name = $moon[1]; + $ore->quantity = $moon[2]; + $ore->solar_system_id = $moon[4]; + $ore->planet_id = $moon[5]; + $ore->save(); + } } - - dd(); } } diff --git a/app/Models/MoonRental/AllianceMoonOre.php b/app/Models/MoonRental/AllianceMoonOre.php index 1d77f64f8..9391d5668 100644 --- a/app/Models/MoonRental/AllianceMoonOre.php +++ b/app/Models/MoonRental/AllianceMoonOre.php @@ -31,5 +31,8 @@ class AllianceMoonOre extends Model 'moon_name', 'ore_type_id', 'ore_name', + 'quantity', + 'solar_system_id', + 'planet_id', ]; } diff --git a/database/migrations/2021_05_28_111608_create_new_moon_rental_tables.php b/database/migrations/2021_05_28_111608_create_new_moon_rental_tables.php index 0ba88a4db..1e92621bc 100644 --- a/database/migrations/2021_05_28_111608_create_new_moon_rental_tables.php +++ b/database/migrations/2021_05_28_111608_create_new_moon_rental_tables.php @@ -31,15 +31,15 @@ class CreateNewMoonRentalTables extends Migration Schema::create('alliance_moons', function (Blueprint $table) { $table->id(); $table->unsignedBigInteger('moon_id'); - $table->string('name'); + $table->string('name')->default('Not Assigned'); $table->unsignedBigInteger('system_id'); - $table->string('system_name'); - $table->decimal('worth_amount'); + $table->string('system_name')->default('Not Assigned'); + $table->decimal('worth_amount')->default(0.00); $table->enum('rented', [ 'No', 'Yes', - ]); - $table->decimal('rental_amount'); + ])->default('No'); + $table->decimal('rental_amount')->default(0.00); $table->timestamps(); }); } @@ -48,9 +48,12 @@ class CreateNewMoonRentalTables extends Migration Schema::create('alliance_moons', function (Blueprint $table) { $table->id(); $table->unsignedBigInteger('moon_id'); - $table->string('moon_name'); + $table->string('moon_name')->default('Not Assigned'); $table->unsignedBigInteger('ore_type_id'); $table->string('ore_name'); + $table->float('quantity'); + $table->unsignedBigInteger('solar_system_id'); + $table->unsignedBigInteger('planet_id'); }); } @@ -58,8 +61,8 @@ class CreateNewMoonRentalTables extends Migration Schema::create('alliance_moon_rentals', function (Blueprint $table) { $table->id(); $table->unsignedBigInteger('moon_id'); - $table->string('moon_name'); - $table->decimal('rental_amount', 20, 2); + $table->string('moon_name')->default('Not Assigned'); + $table->decimal('rental_amount', 20, 2)->default(0.00); $table->date('rental_start')->nullable(); $table->date('rental_end')->nullable(); $table->date('next_billing_date')->nullable();