tethys/app/Models/Coverage.php

74 lines
1.8 KiB
PHP
Raw Normal View History

2019-03-20 17:40:14 +00:00
<?php
namespace App\Models;
use App\Models\Dataset;
use Illuminate\Database\Eloquent\Factories\HasFactory;
2019-03-20 17:40:14 +00:00
use Illuminate\Database\Eloquent\Model;
use DateTimeInterface;
2019-03-20 17:40:14 +00:00
class Coverage extends Model
{
use HasFactory;
2019-03-20 17:40:14 +00:00
protected $table = 'coverage';
public $timestamps = true;
protected $dateFormat = 'Y-m-d H:i:s';
// protected $dateFormat = 'd.m.Y H:i:s';
2019-03-20 17:40:14 +00:00
protected $fillable = [
'elevation_min',
'elevation_max',
'elevation_absolut',
'depth_min',
'depth_max',
2019-03-29 17:29:20 +00:00
'depth_absolut',
'time_min',
'time_max',
'time_absolut',
2020-01-23 16:52:26 +00:00
'x_min', 'x_max', 'y_min', 'y_max',
2019-03-20 17:40:14 +00:00
];
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = [
'time_min',
'time_max',
'time_absolut',
];
2020-01-23 16:52:26 +00:00
public function setTimeAbsolutAttribute($date)
{
2020-01-23 16:52:26 +00:00
$this->attributes['time_absolut'] = empty($date) ? null : \Illuminate\Support\Carbon::createFromFormat('Y-m-d H:i:s', $date);
}
2020-01-23 16:52:26 +00:00
public function setTimeMinAttribute($date)
{
2020-01-23 16:52:26 +00:00
$this->attributes['time_min'] = empty($date) ? null : \Illuminate\Support\Carbon::createFromFormat('Y-m-d H:i:s', $date);
}
2020-01-23 16:52:26 +00:00
public function setTimeMaxAttribute($date)
{
2020-01-23 16:52:26 +00:00
$this->attributes['time_max'] = empty($date) ? null : \Illuminate\Support\Carbon::createFromFormat('Y-m-d H:i:s', $date);
}
/**
* Prepare a date for array / JSON serialization.
*
* @param \DateTimeInterface $date
* @return string
*/
protected function serializeDate(DateTimeInterface $date)
{
return $date->format('Y-m-d H:i:s');
}
/**
* relationship to dataset
*
*
*/
2019-03-20 17:40:14 +00:00
public function dataset()
{
return $this->belongsTo(Dataset::class, 'dataset_id', 'id');
}
}