diff --git a/app/Database/migrations/2020_10_28_081536_modify_pirep_fares.php b/app/Database/migrations/2020_10_28_081536_modify_pirep_fares.php index 8295d235..834bbdb4 100644 --- a/app/Database/migrations/2020_10_28_081536_modify_pirep_fares.php +++ b/app/Database/migrations/2020_10_28_081536_modify_pirep_fares.php @@ -2,6 +2,7 @@ use App\Contracts\Migration; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Schema; class ModifyPirepFares extends Migration @@ -21,8 +22,11 @@ class ModifyPirepFares extends Migration Schema::table('pirep_fares', function (Blueprint $table) { $table->unsignedInteger('fare_id')->change()->nullable()->default(0); - $table->string('code', 50)->unique(); + $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); @@ -33,6 +37,13 @@ class ModifyPirepFares extends Migration * 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() diff --git a/app/Models/PirepFare.php b/app/Models/PirepFare.php index 6a4b9c4d..2970c583 100644 --- a/app/Models/PirepFare.php +++ b/app/Models/PirepFare.php @@ -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');