Skip to content

Commit

Permalink
Add create statements to examples
Browse files Browse the repository at this point in the history
  • Loading branch information
drbyte authored Nov 19, 2023
1 parent 4011bf8 commit eb61a65
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions docs/basic-usage/wildcard-permissions.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ weight: 6

When enabled, wildcard permissions offers you a flexible representation for a variety of permission schemes. The idea
behind wildcard permissions is inspired by the default permission implementation of
[Apache Shiro](https://shiro.apache.org/permissions.html).
[Apache Shiro](https://shiro.apache.org/permissions.html). See the Shiro documentation for more examples.

## Enabling Wildcard Feature
## Enabling Wildcard Features

Wildcard permissions can be enabled in the permission config file:

Expand All @@ -27,11 +27,11 @@ $permission = 'posts.create.1';
The meaning of each part of the string depends on the application layer.

> You can use as many parts as you like. So you are not limited to the three-tiered structure, even though
this is the common use-case, representing {resource}.{action}.{target}.
this is the common use-case, representing `{resource}.{action}.{target}`.

> NOTE: You must actually create the permissions (eg: `posts.create.1`) before you can assign them or check for them.
> **NOTE: You must actually create the wildcarded permissions** (eg: `posts.create.1`) before you can assign them or check for them.
> NOTE: You must create any wildcard permission patterns (eg: `posts.create.*`) before you can assign them or check for them.
> **NOTE: You must create any wildcard permission patterns** (eg: `posts.create.*`) before you can assign them or check for them.
## Using Wildcards

Expand All @@ -47,21 +47,22 @@ Permission::create(['name'=>'posts']);
$user->givePermissionTo('posts');
```

Everyone who is assigned to this permission will be allowed every action on posts. It is not necessary to use a
Given the example above, everyone who is assigned to this permission will be allowed every action on posts. It is not necessary to use a
wildcard on the last part of the string. This is automatically assumed.

```php
// will be true
$user->can('posts.create');
$user->can('posts.edit');
$user->can('posts.delete');
```
```
(Note that the `posts.create` and `posts.edit` and `posts.delete` permissions must also be created.)

## Meaning of the `*` Asterisk
## Meaning of the * Asterisk

The `*` means "ALL". It does **not** mean "ANY".

Thus `can('post.*')` will only pass if the user has been assigned `post.*` explicitly.
Thus `can('post.*')` will only pass if the user has been assigned `post.*` explicitly, and the `post.*` Permission has been created.


## Subparts
Expand All @@ -71,12 +72,15 @@ powerful feature that lets you create complex permission schemes.

```php
// user can only do the actions create, update and view on both resources posts and users
Permission::create(['name'=>'posts,users.create,update,view']);
$user->givePermissionTo('posts,users.create,update,view');

// user can do the actions create, update, view on any available resource
Permission::create(['name'=>'*.create,update,view']);
$user->givePermissionTo('*.create,update,view');

// user can do any action on posts with ids 1, 4 and 6
Permission::create(['name'=>'posts.*.1,4,6']);
$user->givePermissionTo('posts.*.1,4,6');
```

Expand Down

0 comments on commit eb61a65

Please sign in to comment.