set fare classes on aircraft w/ overrides (no admin ui yet)

This commit is contained in:
Nabeel Shahzad
2017-06-10 18:27:19 -05:00
parent dee3503ad6
commit bf910e4549
27 changed files with 859 additions and 88 deletions

View File

@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
/**
* Class Aircraft
*
* @package App\Models
* @version June 9, 2017, 1:06 am UTC
*/
@@ -15,42 +16,46 @@ class Aircraft extends Model
use SoftDeletes;
public $table = 'aircraft';
protected $dates = ['deleted_at'];
public $fillable = [
'aircraft_class_id',
'icao',
'name',
'full_name',
'registration',
'active'
];
public $fillable
= [
'aircraft_class_id',
'icao',
'name',
'full_name',
'registration',
'active',
];
/**
* The attributes that should be casted to native types.
*
* @var array
*/
protected $casts = [
'icao' => 'string',
'name' => 'string',
'full_name' => 'string',
'registration' => 'string',
'active' => 'boolean',
];
protected $casts
= [
'icao' => 'string',
'name' => 'string',
'full_name' => 'string',
'registration' => 'string',
'active' => 'boolean',
];
/**
* Validation rules
*
* @var array
*/
public static $rules = [
'icao' => 'required|max:4',
'name' => 'required',
'full_name' => 'required',
'registration' => 'required',
'active' => 'default:1'
];
public static $rules
= [
'icao' => 'required|max:4',
'name' => 'required',
'full_name' => 'required',
'registration' => 'required',
'active' => 'default:1',
];
/**
* foreign key
@@ -63,8 +68,12 @@ class Aircraft extends Model
);
}
public function fares() {
# aircraft_fare == table name
return $this->belongsToMany('App\Models\Fare', 'aircraft_fare');
public function fares()
{
$r = $this->belongsToMany(
'App\Models\Fare',
'aircraft_fare'
)->withPivot('price', 'cost', 'capacity');
return $r;
}
}

66
app/Models/Fare.php Normal file
View File

@@ -0,0 +1,66 @@
<?php
namespace App\Models;
use Eloquent as Model;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* Class Fare
*
* @package App\Models
* @version June 10, 2017, 4:03 am UTC
*/
class Fare extends Model
{
use SoftDeletes;
public $table = 'fares';
protected $dates = ['deleted_at'];
public $fillable
= [
'code',
'name',
'price',
'cost',
'notes',
'active',
];
/**
* The attributes that should be casted to native types.
*
* @var array
*/
protected $casts
= [
'code' => 'string',
'name' => 'string',
'price' => 'float',
'cost' => 'float',
'notes' => 'string',
'active' => 'boolean',
];
/**
* Validation rules
*
* @var array
*/
public static $rules
= [
'code' => 'required',
'name' => 'required',
'cost' => 'default:0.0',
];
public function aircraft() {
return $this->belongsToMany(
'App\Models\Aircraft',
'aircraft_fare'
)->withPivot('price', 'cost', 'capacity');
}
}