Skip to content

Commit 697f570

Browse files
authored
Merge pull request #606 from kenjis/fix-docs-flters
docs: remove unsupported Filter code sample
2 parents 8f885d2 + ff6527c commit 697f570

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

docs/authorization.md

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
- [can()](#can)
1010
- [inGroup()](#ingroup)
1111
- [hasPermission()](#haspermission)
12-
- [Authorizing via Filters](#authorizing-via-filters)
1312
- [Authorizing via Routes](#authorizing-via-routes)
1413
- [Managing User Permissions](#managing-user-permissions)
1514
- [addPermission()](#addpermission)
@@ -130,28 +129,34 @@ if (! $user->hasPermission('users.create')) {
130129
}
131130
```
132131

133-
#### Authorizing via Filters
132+
#### Authorizing via Routes
134133

135-
You can restrict access to multiple routes through a [Controller Filter](https://codeigniter.com/user_guide/incoming/filters.html). One is provided for both restricting via groups the user belongs to, as well as which permission they need. The filters are automatically registered with the system under the `group` and `permission` aliases, respectively. You can define the protections within **app/Config/Filters.php**:
134+
You can restrict access to a route or route group through a
135+
[Controller Filter](https://codeigniter.com/user_guide/incoming/filters.html).
136136

137-
```php
138-
public $filters = [
139-
'group:admin,superadmin' => ['before' => ['admin/*']],
140-
'permission:users.manage' => ['before' => ['admin/users/*']],
141-
];
142-
```
137+
One is provided for restricting via groups the user belongs to, the other
138+
is for permission they need. The filters are automatically registered with the
139+
system under the `group` and `permission` aliases, respectively.
143140

144-
#### Authorizing via Routes
145-
146-
The filters can also be used on a route or route group level:
141+
You can set the filters within **app/Config/Routes.php**:
147142

148143
```php
149144
$routes->group('admin', ['filter' => 'group:admin,superadmin'], static function ($routes) {
150-
$routes->resource('users');
145+
$routes->group(
146+
'',
147+
['filter' => ['group:admin,superadmin', 'permission:users.manage']],
148+
static function ($routes) {
149+
$routes->resource('users');
150+
}
151+
);
151152
});
152-
153153
```
154154

155+
Note that the options (`filter`) passed to the outer `group()` are not merged with the inner `group()` options.
156+
157+
> **Note** If you set more than one filter to a route, you need to enable
158+
> [Multiple Filters](https://codeigniter.com/user_guide/incoming/routing.html#multiple-filters).
159+
155160
## Managing User Permissions
156161

157162
Permissions can be granted on a user level as well as on a group level. Any user-level permissions granted will

0 commit comments

Comments
 (0)