Completed
Pull Request — develop (#20)
by
unknown
08:28
created

Device::getIpAttribute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
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