2018-02-27 05:16:12 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
2018-03-20 09:50:40 +08:00
|
|
|
use App\Interfaces\Model;
|
2018-02-27 05:16:12 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class Expense
|
2018-03-20 09:50:40 +08:00
|
|
|
* @property int airline_id
|
|
|
|
* @property float amount
|
2018-03-03 07:29:11 +08:00
|
|
|
* @property string name
|
2018-03-17 09:12:56 +08:00
|
|
|
* @property string ref_class
|
|
|
|
* @property string ref_class_id
|
2018-02-27 05:16:12 +08:00
|
|
|
* @package App\Models
|
|
|
|
*/
|
2018-03-20 09:50:40 +08:00
|
|
|
class Expense extends Model
|
2018-02-27 05:16:12 +08:00
|
|
|
{
|
|
|
|
public $table = 'expenses';
|
|
|
|
|
|
|
|
public $fillable = [
|
|
|
|
'airline_id',
|
|
|
|
'name',
|
|
|
|
'amount',
|
|
|
|
'type',
|
|
|
|
'multiplier',
|
2018-03-07 07:15:42 +08:00
|
|
|
'charge_to_user',
|
2018-03-06 11:24:49 +08:00
|
|
|
'ref_class',
|
|
|
|
'ref_class_id',
|
2018-02-27 05:16:12 +08:00
|
|
|
'active',
|
|
|
|
];
|
|
|
|
|
|
|
|
public static $rules = [
|
2018-03-20 09:50:40 +08:00
|
|
|
'active' => 'boolean',
|
|
|
|
'airline_id' => 'integer',
|
|
|
|
'amount' => 'float',
|
|
|
|
'type' => 'integer',
|
|
|
|
'multiplier' => 'bool',
|
|
|
|
'charge_to_user' => 'bool',
|
2018-02-27 05:16:12 +08:00
|
|
|
];
|
|
|
|
|
2018-03-17 09:12:56 +08:00
|
|
|
/**
|
|
|
|
* Get the referring object
|
|
|
|
*/
|
|
|
|
public function getReference()
|
|
|
|
{
|
|
|
|
if (!$this->ref_class || !$this->ref_class_id) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-03-20 09:50:40 +08:00
|
|
|
if ($this->ref_class === __CLASS__) {
|
2018-03-17 09:12:56 +08:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
$klass = new $this->ref_class;
|
2018-03-20 09:50:40 +08:00
|
|
|
|
2018-03-17 09:12:56 +08:00
|
|
|
return $klass->find($this->ref_class_id);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-27 05:16:12 +08:00
|
|
|
/**
|
|
|
|
* Foreign Keys
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function airline()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Airline::class, 'airline_id');
|
|
|
|
}
|
|
|
|
}
|