Completed
Pull Request — master (#82)
by Brandon
02:15
created

Sensor::latestData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace App;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Spatie\Activitylog\Traits\LogsActivity;
7
use Illuminate\Support\Facades\Auth;
8
9
class Sensor extends Model 
10
{
11
    use LogsActivity;
12
13
    protected $table = 'sensors';
14
15
    /**
16
     * Update the updated_at and created_at timestamps?
17
     *
18
     * @var array
19
     */
20
    public $timestamps = false;
21
22
    /**
23
     * The attributes that are mass assignable.
24
     *
25
     * @var array
26
     */
27
    protected $fillable = array('device_id', 'name', 'type');
28
29
    /**
30
     * The attributes that are visible.
31
     *
32
     * @var array
33
     */
34
    protected $visible = array('id', 'device_id', 'name', 'type');
35
36
    /**
37
     * The attributes to log in the Activity Log
38
     *
39
     * @var array
40
     */
41
    protected static $logAttributes = array('id', 'device_id', 'name', 'type');
42
43
    /**
44
     * Only log those that have actually changed after the update.
45
     *
46
     * @var array
47
     */
48
    protected static $logOnlyDirty = true;
49
50
    /**
51
     * Get the device associated with the sensor.
52
     */
53
    public function device()
54
    {
55
        return $this->belongsTo('App\Device');
56
    }
57
58
    /**
59
     * Get the sensor data associated with the sensor.
60
     */
61
    public function data()
62
    {
63
        return $this->hasMany('App\SensorData');
64
    }
65
    
66
    /**
67
     * Get the latest sensor data entry associated with the sensor.
68
     */
69
    public function latestData()
70
    {
71
        return $this->hasOne('App\SensorData')->latest();
72
    }
73
}