Compare commits

...

2 Commits

Author SHA1 Message Date
Nabeel Shahzad
aa8cda89d6 Change model 2020-10-29 12:06:20 -04:00
Nabeel Shahzad
5ba65cf2d1 Initial pirep fares changes #903 2020-10-28 17:11:05 -04:00
2 changed files with 69 additions and 10 deletions

View File

@@ -0,0 +1,52 @@
<?php
use App\Contracts\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class ModifyPirepFares extends Migration
{
/**
* Modify the PIREP fares table so that we can save all of the fares for that particular PIREP
* Basically copy all of those fields over, and then use this table directly, instead of the
* relationship to the fares table
*
* @return void
*/
public function up()
{
/*
* Add the columns we need from the fares table so then this is now "fixed" in time
*/
Schema::table('pirep_fares', function (Blueprint $table) {
$table->unsignedInteger('fare_id')->change()->nullable()->default(0);
$table->string('code', 50);
$table->string('name', 50);
// count is already there
$table->unsignedDecimal('price')->nullable()->default(0.00);
$table->unsignedDecimal('cost')->nullable()->default(0.00);
$table->unsignedInteger('capacity')->nullable()->default(0);
});
/**
* Now iterate through the existing table and copy/update everything
* Some fares might already have been removed deleted so just insert some null/errored
* values for those
*/
$parent_fares = [];
$fares = DB::table('pirep_fares')->get();
foreach ($fares as $fare) {
if (empty($parent_fares[$fare->fare_id])) {
$parent_fares[$fare->fare_id] = DB::table('fares')->where('id', $fare->fare_id)->first();
}
}
}
public function down()
{
}
}

View File

@@ -4,6 +4,14 @@ namespace App\Models;
use App\Contracts\Model;
/**
* @property int code
* @property string name
* @property float cost
* @property float price
* @property int capacity
* @property int count
*/
class PirepFare extends Model
{
public $table = 'pirep_fares';
@@ -11,26 +19,25 @@ class PirepFare extends Model
protected $fillable = [
'pirep_id',
'fare_id',
'code',
'name',
'count',
'price',
'cost',
'capacity',
];
protected $casts = [
'count' => 'integer',
'count' => 'integer',
'price' => 'float',
'cost' => 'float',
'capacity' => 'integer',
];
public static $rules = [
'count' => 'required',
];
/**
* Relationships
*/
public function fare()
{
return $this->belongsTo(Fare::class, 'fare_id');
}
public function pirep()
{
return $this->belongsTo(Pirep::class, 'pirep_id');