1 | <?php |
||
9 | class Device extends Model |
||
10 | { |
||
11 | use SoftDeletes; |
||
12 | |||
13 | /** |
||
14 | * The attributes that should be mutated to dates. |
||
15 | * |
||
16 | * @var array |
||
17 | */ |
||
18 | protected $dates = [ |
||
19 | 'deleted_at' |
||
20 | ]; |
||
21 | |||
22 | /** |
||
23 | * The attributes that should be hidden for arrays. |
||
24 | * |
||
25 | * @var array |
||
26 | */ |
||
27 | protected $hidden = ['token']; |
||
28 | |||
29 | /** |
||
30 | * The attributes that are mass assignable. |
||
31 | * |
||
32 | * @var array |
||
33 | */ |
||
34 | protected $fillable = [ |
||
35 | 'name', 'location_id', 'uuid', 'version', 'hostname', 'ip', 'mac_address', 'time', |
||
36 | 'cover_status', 'error_msg', 'limitsw_open', 'limitsw_closed', |
||
37 | 'light_in', 'light_out', 'cpu_temp', 'temperature', 'humidity' |
||
38 | ]; |
||
39 | |||
40 | /** |
||
41 | * The attributes that are for timestamps. |
||
42 | * |
||
43 | * @var array |
||
44 | */ |
||
45 | public $timestamps = false; |
||
46 | |||
47 | /** |
||
48 | * Get the location for the device |
||
49 | */ |
||
50 | public function location() |
||
54 | |||
55 | /** |
||
56 | * Get the site for the device |
||
57 | */ |
||
58 | public function site() |
||
62 | |||
63 | /** |
||
64 | * Update the device with the matching id with a new location id |
||
65 | * |
||
66 | * @param int $id |
||
67 | * @param int $location_id |
||
68 | */ |
||
69 | public function updateLocationID($id, $location_id) |
||
76 | |||
77 | /** |
||
78 | * Get all the devices with the supplied location id |
||
79 | * |
||
80 | * @param int $location_id |
||
81 | * @return Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection |
||
82 | */ |
||
83 | public function getDevicesBasedOnLocation($location_id) |
||
87 | |||
88 | /** |
||
89 | * Get the first device with the supplied location id |
||
90 | * |
||
91 | * @param int $location_id |
||
92 | * @return Device|Illuminate\Database\Eloquent\Model |
||
93 | */ |
||
94 | public function getFirstDeviceBasedOnLocation($location_id) |
||
98 | |||
99 | /** |
||
100 | * Create a new API token for the device. |
||
101 | */ |
||
102 | public function generateToken() |
||
109 | |||
110 | /** |
||
111 | * Get a device by uuid |
||
112 | * |
||
113 | * @param string $uuid |
||
114 | * @return Device|Illuminate\Database\Eloquent\Model |
||
115 | */ |
||
116 | public function getDeviceByUUID($uuid) |
||
120 | } |
||
121 |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: