@@ -18,7 +18,7 @@ Provide a simple method of managing ACL in a Laravel application built on the
18
18
19
19
## Requirements
20
20
- PHP >=7.1.3
21
- - Laravel >= 5.4
21
+ - Laravel >= 5.5
22
22
- Bootstrap 3 (needs to be included in your layout file)
23
23
- FontAwesome 4 (needs to be included in your layout file)
24
24
@@ -34,23 +34,14 @@ Install via composer:
34
34
composer require genealabs/laravel-governor
35
35
```
36
36
37
- ** ONLY FOR LARVEL 5.4 AND LOWER:** Add the service provider to your app.php config file:
38
- ``` php
39
- 'providers' => [
40
- // [...]
41
- GeneaLabs\LaravelGovernor\Providers\Service::class,
42
- // [...]
43
- ],
44
- ```
45
-
46
37
## Implementation
47
38
1 . First we need to update the database by running the migrations and data seeders:
48
39
``` sh
49
40
php artisan migrate
50
41
php artisan db:seed --class=LaravelGovernorDatabaseSeeder
51
42
```
52
43
53
- 2. If you are starting out with an empty database , run your seeders now:
44
+ 2. If you have seeders of your own , run them now:
54
45
` ` ` sh
55
46
php artisan db:seed
56
47
` ` `
@@ -73,7 +64,8 @@ composer require genealabs/laravel-governor
73
64
class User extends Authenticatable
74
65
{
75
66
use Governable;
76
- // [...]
67
+ // [...]
68
+ }
77
69
` ` `
78
70
79
71
# ## Configuration
@@ -142,6 +134,40 @@ We recommend making a custom 403 error page to let the user know they don't have
142
134
https://laravel.com/docs/5.4/errors#custom-http-error-pages for more details on
143
135
how to set those up.
144
136
137
+ ### Authorization API
138
+ You can check a user' s ability to perform certain actions via a public API. It
139
+ is recommended to use Laravel Passport to maintain session state between your
140
+ client and your backend. Here' s an example that checks if the currently logged
141
+ in user can create `GeneaLabs\LaravelGovernor\Role` model records:
142
+
143
+ ```php
144
+ $response = $this
145
+ ->json(
146
+ "GET",
147
+ route(' genealabs.laravel-governor.api.user-can.show' , "create"),
148
+ [
149
+ "model" => "GeneaLabs\LaravelGovernor\Role",
150
+ ]
151
+ );
152
+ ```
153
+
154
+ This next example checks if the user can edit `GeneaLabs\LaravelGovernor\Role`
155
+ model records:
156
+ ```php
157
+ $response = $this
158
+ ->json(
159
+ "GET",
160
+ route(' genealabs.laravel-governor.api.user-can.show' , "edit"),
161
+ [
162
+ "model" => "GeneaLabs\LaravelGovernor\Role",
163
+ "primary-key" => 1,
164
+ ]
165
+ );
166
+ ```
167
+
168
+ The abilities `inspect`, `edit`, and `remove`, except `create` and `view`,
169
+ require the primary key to be passed.
170
+
145
171
## Examples
146
172
### Config File
147
173
```php
@@ -269,3 +295,9 @@ class MyModelPolicy extends LaravelGovernorPolicy
269
295
}
270
296
}
271
297
` ` `
298
+
299
+ # # Update Process
300
+ # ## 0.5 to 0.6
301
+ 1. If you were extending ` GeneaLabs\L aravelGovernor\P olicies\L aravelGovernorPolicy` ,
302
+ change to extend ` GeneaLabs\L aravelGovernor\P olicies\B asePolicy` ;
303
+ 2. Support for version of Laravel lower than 5.5 has been dropped.
0 commit comments