1 | <?php namespace Arcanesoft\Auth\Models; |
||
16 | class Role extends BaseRoleModel |
||
|
|||
17 | { |
||
18 | /* ----------------------------------------------------------------- |
||
19 | | Constants |
||
20 | | ----------------------------------------------------------------- |
||
21 | */ |
||
22 | |||
23 | const ADMINISTRATOR = 'administrator'; |
||
24 | const MODERATOR = 'moderator'; |
||
25 | const MEMBER = 'member'; |
||
26 | |||
27 | /* ----------------------------------------------------------------- |
||
28 | | Traits |
||
29 | | ----------------------------------------------------------------- |
||
30 | */ |
||
31 | |||
32 | use Presenters\RolePresenter; |
||
33 | |||
34 | /* ----------------------------------------------------------------- |
||
35 | | Relationships |
||
36 | | ----------------------------------------------------------------- |
||
37 | */ |
||
38 | |||
39 | /** |
||
40 | * Role belongs to many users. |
||
41 | * |
||
42 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
||
43 | */ |
||
44 | public function users() |
||
48 | |||
49 | /* ----------------------------------------------------------------- |
||
50 | | Scopes |
||
51 | | ----------------------------------------------------------------- |
||
52 | */ |
||
53 | |||
54 | /** |
||
55 | * Scope only with administrator role. |
||
56 | * |
||
57 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
58 | * |
||
59 | * @return \Illuminate\Database\Eloquent\Builder |
||
60 | */ |
||
61 | public function scopeAdmin(Builder $query) |
||
65 | |||
66 | /** |
||
67 | * Scope only with moderator role. |
||
68 | * |
||
69 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
70 | * |
||
71 | * @return \Illuminate\Database\Eloquent\Builder |
||
72 | */ |
||
73 | public function scopeModerator(Builder $query) |
||
77 | |||
78 | /** |
||
79 | * Scope only with member role. |
||
80 | * |
||
81 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
82 | * |
||
83 | * @return \Illuminate\Database\Eloquent\Builder |
||
84 | */ |
||
85 | public function scopeMember(Builder $query) |
||
89 | |||
90 | /* ----------------------------------------------------------------- |
||
91 | | Main Methods |
||
92 | | ----------------------------------------------------------------- |
||
93 | */ |
||
94 | |||
95 | /** |
||
96 | * Get a role from a hashed id or fail if not found. |
||
97 | * |
||
98 | * @param string $hashedId |
||
99 | * |
||
100 | * @return self |
||
101 | * |
||
102 | * @throws \Illuminate\Database\Eloquent\ModelNotFoundException |
||
103 | */ |
||
104 | public static function firstHashedOrFail($hashedId) |
||
108 | |||
109 | /** |
||
110 | * Make the slug. |
||
111 | * |
||
112 | * @param string $value |
||
113 | * |
||
114 | * @return string |
||
115 | */ |
||
116 | public function makeSlugName($value) |
||
120 | } |
||
121 |