heizung/app/Models/Reading.php

12 lines
588 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Reading extends Model {
public $timestamps = false;
protected $fillable = ['device_id','metric','value','value_text','recorded_at'];
protected $casts = ['value'=>'decimal:3','recorded_at'=>'datetime'];
public function device(): BelongsTo { return $this->belongsTo(Device::class); }
public function scopeMetric($q, string $metric) { return $q->where('metric',$metric); }
public function scopeSince($q, $ts) { return $q->where('recorded_at','>=',$ts); }
}