b9993b9c23
* Set expenses on specific flight types #348 * Formatting * Use strict check for in_array
82 lines
1.7 KiB
PHP
82 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Contracts\Model;
|
|
use App\Models\Traits\ReferenceTrait;
|
|
|
|
/**
|
|
* @property int airline_id
|
|
* @property float amount
|
|
* @property string name
|
|
* @property string type
|
|
* @property string flight_type
|
|
* @property string ref_model
|
|
* @property string ref_model_id
|
|
*
|
|
* @mixin \Illuminate\Database\Eloquent\Builder
|
|
*/
|
|
class Expense extends Model
|
|
{
|
|
use ReferenceTrait;
|
|
|
|
public $table = 'expenses';
|
|
|
|
protected $fillable = [
|
|
'airline_id',
|
|
'name',
|
|
'amount',
|
|
'type',
|
|
'flight_type',
|
|
'multiplier',
|
|
'charge_to_user',
|
|
'ref_model',
|
|
'ref_model_id',
|
|
'active',
|
|
];
|
|
|
|
public static $rules = [
|
|
'active' => 'boolean',
|
|
'airline_id' => 'integer',
|
|
'amount' => 'float',
|
|
'multiplier' => 'bool',
|
|
'charge_to_user' => 'bool',
|
|
];
|
|
|
|
/**
|
|
* 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);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Foreign Keys
|
|
*/
|
|
public function airline()
|
|
{
|
|
return $this->belongsTo(Airline::class, 'airline_id');
|
|
}
|
|
}
|