Completed
Push — master ( 8da79d...fd43b2 )
by ARCANEDEV
03:03
created

PermissionsGroup::getHashedIdAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php namespace Arcanesoft\Auth\Models;
2
3
use \Arcanedev\LaravelAuth\Models\PermissionsGroup as BasePermissionsGroupModel;
4
5
/**
6
 * Class     PermissionsGroup
7
 *
8
 * @package  Arcanesoft\Auth\Models
9
 * @author   ARCANEDEV <[email protected]>
10
 *
11
 * @property  string  hashed_id
12
 */
13
class PermissionsGroup extends BasePermissionsGroupModel
14
{
15
    /* ------------------------------------------------------------------------------------------------
16
     |  Getters & Setters
17
     | ------------------------------------------------------------------------------------------------
18
     */
19
    /**
20
     * Get the permissions group hash id.
21
     *
22
     * @return string
23
     */
24
    public function getHashedIdAttribute()
25
    {
26
        return self::hasher()->encode($this->id);
27
    }
28
29
    /* ------------------------------------------------------------------------------------------------
30
     |  Main Function
31
     | ------------------------------------------------------------------------------------------------
32
     */
33
    /**
34
     * Get a permission from a hashed id or fail if not found.
35
     *
36
     * @param  string  $hashedId
37
     *
38
     * @return self
39
     *
40
     * @throws \Illuminate\Database\Eloquent\ModelNotFoundException
41
     */
42
    public static function firstHashedOrFail($hashedId)
43
    {
44
        $id = self::hasher()->decode($hashedId);
45
46
        return self::where('id', $id)->firstOrFail();
47
    }
48
49
    /* ------------------------------------------------------------------------------------------------
50
     |  Other Functions
51
     | ------------------------------------------------------------------------------------------------
52
     */
53
    /**
54
     * Get the hasher.
55
     *
56
     * @return \Arcanedev\Hasher\Contracts\HashManager
57
     */
58
    protected static function hasher()
59
    {
60
        return hasher();
61
    }
62
}
63