1
|
|
|
<?php namespace Arcanesoft\Auth\Models; |
2
|
|
|
|
3
|
|
|
use Arcanedev\LaravelAuth\Models\Permission as BasePermissionModel; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class Permission |
7
|
|
|
* |
8
|
|
|
* @package Arcanesoft\Auth\Models |
9
|
|
|
* @author ARCANEDEV <[email protected]> |
10
|
|
|
*/ |
11
|
|
|
class Permission extends BasePermissionModel |
12
|
|
|
{ |
13
|
|
|
/* ------------------------------------------------------------------------------------------------ |
14
|
|
|
| Getters & Setters |
15
|
|
|
| ------------------------------------------------------------------------------------------------ |
16
|
|
|
*/ |
17
|
|
|
/** |
18
|
|
|
* Get the role 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 permission 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
|
|
|
/** |
48
|
|
|
* Get the ids of all permissions. |
49
|
|
|
* |
50
|
|
|
* @return \Illuminate\Database\Eloquent\Collection |
51
|
|
|
*/ |
52
|
|
|
public static function getIds() |
53
|
|
|
{ |
54
|
|
|
return self::orderBy('id')->lists('id'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/* ------------------------------------------------------------------------------------------------ |
58
|
|
|
| Check Functions |
59
|
|
|
| ------------------------------------------------------------------------------------------------ |
60
|
|
|
*/ |
61
|
|
|
/** |
62
|
|
|
* Check if permission has a group. |
63
|
|
|
* |
64
|
|
|
* @return bool |
65
|
|
|
*/ |
66
|
|
|
public function hasGroup() |
67
|
|
|
{ |
68
|
|
|
return $this->group_id !== 0; |
|
|
|
|
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.