|
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 Site 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' |
|
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' |
|
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 locations for the site. |
|
54
|
|
|
*/ |
|
55
|
|
|
public function locations() |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->hasMany('App\Location'); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Get the devices for the site. |
|
62
|
|
|
*/ |
|
63
|
|
|
public function devices() |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->hasManyThrough('App\Device', 'App\Location'); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Accessor: Get the site's last update time in seconds/minutes/hours since update or converted to user |
|
70
|
|
|
* friendly readable format. |
|
71
|
|
|
* If the time is less then a day old then display time since it last updated |
|
72
|
|
|
* If the time is greater then a day old then display the time in the format of Month day, year 12hour:mins am/pm |
|
73
|
|
|
* and using the user's preferred timezone |
|
74
|
|
|
* |
|
75
|
|
|
* |
|
76
|
|
|
* @return string |
|
77
|
|
|
*/ |
|
78
|
|
View Code Duplication |
public function getUpdatedAtHumanAttribute() |
|
79
|
|
|
{ |
|
80
|
|
|
if ($this->updated_at->diffInDays() > 0) { |
|
81
|
|
|
return $this->updated_at->setTimezone(Auth::user()->timezone)->format('M d, Y h:i a'); |
|
82
|
|
|
} else { |
|
83
|
|
|
return $this->updated_at->diffForHumans(); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Accessor: Get the site's creation time in seconds/minutes/hours since update or converted to user |
|
89
|
|
|
* friendly readable format. |
|
90
|
|
|
* If the time is less then a day old then display time since creation |
|
91
|
|
|
* If the time is greater then a day old then display the time in the format of Month day, year 12hour:mins am/pm |
|
92
|
|
|
* and using the user's preferred timezone |
|
93
|
|
|
* |
|
94
|
|
|
* |
|
95
|
|
|
* @return string |
|
96
|
|
|
*/ |
|
97
|
|
View Code Duplication |
public function getCreatedAtHumanAttribute() |
|
98
|
|
|
{ |
|
99
|
|
|
if ($this->created_at->diffInDays() > 0) { |
|
100
|
|
|
return $this->created_at->setTimezone(Auth::user()->timezone)->format('M d, Y h:i a'); |
|
101
|
|
|
} else { |
|
102
|
|
|
return $this->created_at->diffForHumans(); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|