Completed
Pull Request — master (#2)
by ARCANEDEV
03:02
created

PermissionsGroup::firstHashedOrFail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

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 6
ccs 0
cts 5
cp 0
rs 9.4286
cc 1
eloc 3
nc 1
nop 1
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 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 = head(hasher()->decode($hashedId));
45
46
        return self::where('id', $id)->firstOrFail();
47
    }
48
}
49