You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/usage/concepts.rst
+8-10Lines changed: 8 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -139,22 +139,19 @@ Now we can check for roles and permissions simply by doing:
139
139
$user->hasRole('admin'); // true
140
140
$user->can('edit-user'); // false
141
141
$user->can('create-post'); // true
142
-
$user->hasPermission('create-post'); // true
143
-
$user->isAbleTo('create-post'); // true
144
142
145
143
.. NOTE::
146
-
The ``can``, ``hasPermission`` and ``isAbleTo`` methods have the same objective, to check user's permissions.
144
+
If you want, you can use the ``hasPermission`` and ``isAbleTo`` methods instead of the ``can`` method.
147
145
148
-
Inside Laratrust code the ``hasPermission`` method is used intead of the ``can`` method, so if you want to use the Authorizable trait you can use it without any problem (if you didn't use the Laratrust can method). To use the Authorizable trait check :ref:`troubleshooting`.
146
+
.. NOTE::
147
+
If you want to use the Authorizable trait alongside Laratrust please check :ref:`troubleshooting`.
149
148
150
-
Both ``hasRole()``, ``can()``, ``hasPermission()``, ``isAbleTo()`` can receive an array of roles & permissions to check:
149
+
Both ``hasRole()`` and ``can()`` can receive an array of roles & permissions to check:
By default, if any of the roles or permissions are present for a user then the method will return true.
160
157
Passing ``true`` as a second parameter instructs the method to require **all** of the items:
@@ -165,8 +162,6 @@ Passing ``true`` as a second parameter instructs the method to require **all** o
165
162
$user->hasRole(['owner', 'admin'], true); // false, user does not have admin role
166
163
$user->can(['edit-user', 'create-post']); // true
167
164
$user->can(['edit-user', 'create-post'], true); // false, user does not have edit-user permission
168
-
$user->hasPermission(['edit-user', 'create-post'], true); // false, user does not have edit-user permission
169
-
$user->isAbleTo(['edit-user', 'create-post'], true); // false, user does not have edit-user permission
170
165
171
166
You can have as many \ ``Role``\s as you want for each ``User`` and vice versa.
172
167
@@ -180,7 +175,10 @@ The ``Laratrust`` class has shortcuts to both ``can()`` and ``hasRole()`` for th
180
175
// is identical to
181
176
182
177
Auth::user()->hasRole('role-name');
183
-
Auth::user()->can('permission-name');
178
+
Auth::user()->hasPermission('permission-name');
179
+
180
+
.. WARNING::
181
+
There aren't ``Laratrust::hasPermission`` or ``Laratrust::isAbleTo`` facade methods, because you can use the ``Laratrust::can`` even when using the ``Authorizable`` trait.
184
182
185
183
You can also use placeholders (wildcards) to check any matching permission by doing:
0 commit comments