1 | <?php namespace Arcanedev\LaravelAuth\Models\Traits; |
||
17 | trait Roleable |
||
18 | { |
||
19 | /* ----------------------------------------------------------------- |
||
20 | | Getters & Setters |
||
21 | | ----------------------------------------------------------------- |
||
22 | */ |
||
23 | |||
24 | /** |
||
25 | * Get the active roles collection. |
||
26 | * |
||
27 | * @return \Illuminate\Database\Eloquent\Collection |
||
28 | */ |
||
29 | 54 | public function getActiveRolesAttribute() |
|
35 | |||
36 | /* ----------------------------------------------------------------- |
||
37 | | Check Methods |
||
38 | | ----------------------------------------------------------------- |
||
39 | */ |
||
40 | |||
41 | /** |
||
42 | * Check if user has the given role (Role Model or Id). |
||
43 | * |
||
44 | * @param \Arcanesoft\Contracts\Auth\Models\Role|int $id |
||
45 | * |
||
46 | * @return bool |
||
47 | */ |
||
48 | 54 | public function hasRole($id) |
|
54 | |||
55 | /** |
||
56 | * Check if has all roles. |
||
57 | * |
||
58 | * @param \Illuminate\Support\Collection|array $roles |
||
59 | * @param \Illuminate\Support\Collection &$failed |
||
60 | * |
||
61 | * @return bool |
||
62 | */ |
||
63 | 6 | public function isAll($roles, &$failed = null) |
|
69 | |||
70 | /** |
||
71 | * Check if has at least one role. |
||
72 | * |
||
73 | * @param \Illuminate\Support\Collection|array $roles |
||
74 | * @param \Illuminate\Support\Collection &$failed |
||
75 | * |
||
76 | * @return bool |
||
77 | */ |
||
78 | 15 | public function isOne($roles, &$failed = null) |
|
88 | |||
89 | /** |
||
90 | * Check if has a role by its slug. |
||
91 | * |
||
92 | * @param string $slug |
||
93 | * |
||
94 | * @return bool |
||
95 | */ |
||
96 | 21 | public function hasRoleSlug($slug) |
|
104 | |||
105 | /* ----------------------------------------------------------------- |
||
106 | | Other Methods |
||
107 | | ----------------------------------------------------------------- |
||
108 | */ |
||
109 | /** |
||
110 | * Load all roles. |
||
111 | * |
||
112 | * @param bool $load |
||
113 | * |
||
114 | * @return self |
||
115 | */ |
||
116 | 60 | protected function loadRoles($load = true) |
|
120 | } |
||
121 |