phpvms/app/Models/Expense.php

71 lines
1.4 KiB
PHP
Raw Normal View History

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