2018-02-27 05:16:12 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
2018-08-27 00:40:04 +08:00
|
|
|
|
2019-07-16 03:44:31 +08:00
|
|
|
use App\Contracts\Model;
|
2018-04-02 11:26:20 +08:00
|
|
|
use App\Models\Traits\ReferenceTrait;
|
2018-02-27 05:16:12 +08:00
|
|
|
|
|
|
|
/**
|
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
|
2020-02-12 23:40:52 +08:00
|
|
|
* @property string type
|
|
|
|
* @property string flight_type
|
2018-04-02 03:32:01 +08:00
|
|
|
* @property string ref_model
|
|
|
|
* @property string ref_model_id
|
2020-02-12 23:40:52 +08:00
|
|
|
*
|
|
|
|
* @mixin \Illuminate\Database\Eloquent\Builder
|
2018-02-27 05:16:12 +08:00
|
|
|
*/
|
2018-03-20 09:50:40 +08:00
|
|
|
class Expense extends Model
|
2018-02-27 05:16:12 +08:00
|
|
|
{
|
2018-04-02 11:26:20 +08:00
|
|
|
use ReferenceTrait;
|
|
|
|
|
2018-02-27 05:16:12 +08:00
|
|
|
public $table = 'expenses';
|
|
|
|
|
2018-03-21 08:40:19 +08:00
|
|
|
protected $fillable = [
|
2018-02-27 05:16:12 +08:00
|
|
|
'airline_id',
|
|
|
|
'name',
|
|
|
|
'amount',
|
|
|
|
'type',
|
2020-02-12 23:40:52 +08:00
|
|
|
'flight_type',
|
2018-02-27 05:16:12 +08:00
|
|
|
'multiplier',
|
2018-03-07 07:15:42 +08:00
|
|
|
'charge_to_user',
|
2018-04-02 03:32:01 +08:00
|
|
|
'ref_model',
|
|
|
|
'ref_model_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',
|
|
|
|
'multiplier' => 'bool',
|
|
|
|
'charge_to_user' => 'bool',
|
2018-02-27 05:16:12 +08:00
|
|
|
];
|
|
|
|
|
2020-02-12 23:40:52 +08:00
|
|
|
/**
|
|
|
|
* flight_type is stored a comma delimited list in table. Retrieve it as an array
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getFlightTypeAttribute()
|
|
|
|
{
|
|
|
|
if (empty(trim($this->attributes['flight_type']))) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
return explode(',', $this->attributes['flight_type']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make sure the flight type is stored a comma-delimited list in the table
|
|
|
|
*
|
|
|
|
* @param string $value
|
|
|
|
*/
|
|
|
|
public function setFlightTypeAttribute($value)
|
|
|
|
{
|
|
|
|
if (is_array($value)) {
|
|
|
|
$this->attributes['flight_type'] = implode(',', $value);
|
|
|
|
} else {
|
|
|
|
$this->attributes['flight_type'] = trim($value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-27 05:16:12 +08:00
|
|
|
/**
|
|
|
|
* Foreign Keys
|
|
|
|
*/
|
|
|
|
public function airline()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Airline::class, 'airline_id');
|
|
|
|
}
|
|
|
|
}
|