Change model

This commit is contained in:
Nabeel Shahzad
2020-10-29 12:06:20 -04:00
parent 5ba65cf2d1
commit aa8cda89d6
2 changed files with 29 additions and 11 deletions

View File

@@ -2,6 +2,7 @@
use App\Contracts\Migration; use App\Contracts\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
class ModifyPirepFares extends Migration class ModifyPirepFares extends Migration
@@ -21,8 +22,11 @@ class ModifyPirepFares extends Migration
Schema::table('pirep_fares', function (Blueprint $table) { Schema::table('pirep_fares', function (Blueprint $table) {
$table->unsignedInteger('fare_id')->change()->nullable()->default(0); $table->unsignedInteger('fare_id')->change()->nullable()->default(0);
$table->string('code', 50)->unique(); $table->string('code', 50);
$table->string('name', 50); $table->string('name', 50);
// count is already there
$table->unsignedDecimal('price')->nullable()->default(0.00); $table->unsignedDecimal('price')->nullable()->default(0.00);
$table->unsignedDecimal('cost')->nullable()->default(0.00); $table->unsignedDecimal('cost')->nullable()->default(0.00);
$table->unsignedInteger('capacity')->nullable()->default(0); $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 * Some fares might already have been removed deleted so just insert some null/errored
* values for those * 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() public function down()

View File

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