Completed
Pull Request — develop (#7)
by
unknown
08:55
created

Devices::getIpAttribute()   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
        return inet_ntop( $ip );
22
    }
23
24
    public function setIpAttribute( $ip )
25
    {
26
        $this->attributes['ip'] = inet_pton( $ip );
27
    }
28
29
    // -- Define Reletionships --
30
31
    /**
32
     * Returns a list of users that can access this device
33
     */
34
    public function users() {
35
        return $this->belongsToMany('App\User', 'devices_perms', 'device_id', 'user_id');
36
    }
37
}
38
39