Completed
Pull Request — master (#96)
by Brandon
02:26
created

Location::createLocation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 9
ccs 0
cts 6
cp 0
rs 9.6666
cc 1
eloc 6
nc 1
nop 2
crap 2
1
<?php
2
3
namespace App;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Support\Facades\DB;
7
use Spatie\Activitylog\Traits\LogsActivity;
8
9
class Location extends Model
10
{
11
    use LogsActivity;
12
    
13
    /**
14
     * The attributes that are mass assignable.
15
     *
16
     * @var array
17
     */
18
    protected $fillable = [
19
        'name', 'site_id'
20
    ];
21
    
22
    /**
23
     * The attributes to ignore in the Activity Log
24
     *
25
     * @var array
26
     */
27
    protected static $ignoreChangedAttributes = ['updated_at'];
28
    
29
    /**
30
     * The attributes to log in the Activity Log
31
     *
32
     * @var array
33
     */
34
    protected static $logAttributes = [
35
        'name', 'site_id'
36
    ];
37
    
38
    /**
39
     * Only log those that have actually changed after the update.
40
     *
41
     * @var array
42
     */
43
    protected static $logOnlyDirty = true;
44
    
45
    /**
46
     * Update the updated_at and created_at timestamps?
47
     *
48
     * @var array
49
     */
50
    public $timestamps = true;
51
    
52
    /**
53
     * Get the site for the location
54
     */
55
    public function site()
56
    {
57
        return $this->belongsTo('App\Site', 'site_id');
58
    }
59
    
60
    /**
61
     * Get devices for the location
62
     */
63
    public function devices()
64
    {
65
        return $this->hasMany('App\Device');
66
    }
67
    
68
    /**
69
     * Scope a query to only include locations belonging to a given site
70
     *
71
     * @param \Illuminate\Database\Eloquent\Builder $query
72
     * @param int $site_id
73
     * @return \Illuminate\Database\Eloquent\Builder
74
     */
75
    public function scopeBySite($query, $site_id)
76
    {
77
        return $query->where('site_id', $site_id);
78
    }
79
}
80