Completed
Push — master ( 49a6f0...9c36f0 )
by ARCANEDEV
04:39
created

Role::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\Role as BaseRoleModel;
4
5
/**
6
 * Class     Role
7
 *
8
 * @package  Arcanesoft\Auth\Models
9
 * @author   ARCANEDEV <[email protected]>
10
 */
11
class Role extends BaseRoleModel
12
{
13
    /* ------------------------------------------------------------------------------------------------
14
     |  Getters & Setters
15
     | ------------------------------------------------------------------------------------------------
16
     */
17
    /**
18
     * Get the user hash id.
19
     *
20
     * @return string
21
     */
22
    public function getHashedIdAttribute()
23
    {
24
        return hasher()->encode($this->id);
25
    }
26
27
    /* ------------------------------------------------------------------------------------------------
28
     |  Main Function
29
     | ------------------------------------------------------------------------------------------------
30
     */
31
    /**
32
     * Get a user from a hashed id or fail if not found.
33
     *
34
     * @param  string  $hashedId
35
     *
36
     * @return self
37
     *
38
     * @throws \Illuminate\Database\Eloquent\ModelNotFoundException
39
     */
40
    public static function firstHashedOrFail($hashedId)
41
    {
42
        $id = head(hasher()->decode($hashedId));
43
44
        return self::where('id', $id)->firstOrFail();
45
    }
46
}
47