Completed
Push — develop ( 463860...5f1168 )
by Neil
06:57
created

Device::users()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace App;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class Device extends Model
8
{
9
    protected $table = 'devices';
10
    protected $primaryKey = 'device_id';
11
12
    /**
13
     * Indicates if the model should be timestamped.
14
     *
15
     * @var bool
16
     */
17
    public $timestamps = false;
18
19
    public function getIpAttribute($ip)
20
    {
21
        if (!empty($ip)) {
22
            return inet_ntop($ip);
23
        }
24
    }
25
26
    public function setIpAttribute($ip)
27
    {
28
        $this->attributes['ip'] = inet_pton($ip);
29
    }
30
31
    // -- Define Reletionships --
32
33
    /**
34
     * Returns a list of users that can access this device
35
     */
36
    public function users() {
37
        return $this->belongsToMany('App\User', 'devices_perms', 'device_id', 'user_id');
38
    }
39
}
40