Completed
Push — develop ( fe1589...9aaff5 )
by Neil
04:59
created

Devices::setIpAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace App;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class Devices 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