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: README.md
+6-2Lines changed: 6 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,6 +23,10 @@ You can install the package via composer:
23
23
composer require binaryk/laravel-restify
24
24
```
25
25
26
+
## Playground
27
+
28
+
You can find a playground in the [Restify Demo GitHub repository](https://github.com/BinarCode/restify-demo).
29
+
26
30
## Videos
27
31
28
32
If you are a visual learner, checkout [our video course](https://www.binarcode.com/learn/restify) for the Laravel Restify.
@@ -87,11 +91,11 @@ Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
87
91
88
92
### Security
89
93
90
-
If you discover any security related issues, please email eduard.lupacescu@binarcode.com instead of using the issue tracker.
94
+
If you discover any security related issues, please email eduard.lupacescu@binarcode.comor [message me on twitter](https://twitter.com/LupacescuEuard)instead of using the issue tracker.
Copy file name to clipboardExpand all lines: UPGRADING.md
+7Lines changed: 7 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,11 @@
1
1
# Upgrading
2
2
3
+
## From 7.3.1 to 7.4.0
4
+
5
+
## Breaking
6
+
7
+
- The `$eagerState` repository property is now private, and it is of type `null|string` because it holds the parent repository that renders it.
8
+
3
9
## From 6.x to 7.x
4
10
5
11
High impact:
@@ -13,6 +19,7 @@ High impact:
13
19
-`$defaultPerPage` and `$defaultRelatablePerPage` has a type of `int`, if you override this make sure you add `int` type
14
20
-`eagerState` method was deleted from the repository, there is no need to call it anymore, the repository will be resolved automatically
15
21
-`$prefix` property requires a `string` type
22
+
-`resolveShowMeta` is not inherited for the `resolveIndexMeta` anymore, both methods are now using `policyMeta` method, so override the `policyMeta` instead. This could be simply solved if you replace in all repositories `resolveShowMeta` with `policyMeta`.
16
23
- Relations that are present into `include` or `related` will be preloaded, so if you didn't specify a repository to serialize the related relationship, and you're looking for the Eloquent to resolve it, it will not invoke the `restify.casts.related` cast anymore, instead it'll load the relationship as it. This has a performance reason under the hood.
17
24
- Since related relationships will be preloaded, the format of the belongs to will be changed now. If you didn't specify the repository to serialize the `belongsTo` relationship, it'll be serialized as an object, not array anymore:
The `classic` approach is good, however, it has a few limitations. Firstly, you have to manually take care of the route `middleware`, the testability for these endpoints should be done separately which is hard to maintain. And finally, the endpoint is disconnected from the repository, which makes it feel out of context so has a bad readability.
25
+
The `classic` approach is good. However, it has a few limitations. First, you have to manually take care of the `middleware` route, as the testability for these endpoints should be done separately, which might be hard to maintain. Ultimately, the endpoint is disconnected from the repository, which makes it feel out of context so it has a bad readability.
26
26
27
-
So, code readability, testability and maintainability become hard.
27
+
On that wise, code readability, testability and maintainability may become hard.
28
28
29
29
## Action definition
30
30
31
-
The action is nothing more than a class, that extends the `Binaryk\LaravelRestify\Actions\Action` abstract class.
31
+
The action is nothing more than a class that extends the `Binaryk\LaravelRestify\Actions\Action` abstract class.
32
32
33
-
It could be generated by using the command:
33
+
It could be generated by using the following command:
The `action` query param value is the `ke-bab` form of the filter class name by default, or a custom `$uriKey`[defined in the action](#custom-uri-key)
99
99
100
100
101
-
The payload could be any type of json data, however, if you're using an [index-action](#index-actions), you are required to pass the `repositories` key, which represents the list of model keys we apply the action:
101
+
The payload could be any type of json data. However, if you're using an [index-action](#index-actions), you are required to pass the `repositories` key, which represents the list of model keys that we apply to this action:
102
102
103
103
```json
104
104
{
@@ -108,7 +108,7 @@ The payload could be any type of json data, however, if you're using an [index-a
108
108
109
109
### Handle action
110
110
111
-
As soon the action is called, the handled method will be invoked with the `$request` and list of models matching the keys passed via `repositories`:
111
+
As soon the action is called, the handled method will be invoked with the `$request` and a list of models matching the keys passed via `repositories`:
112
112
113
113
```php
114
114
public function handle(ActionRequest $request, Collection $models)
@@ -121,7 +121,7 @@ public function handle(ActionRequest $request, Collection $models)
121
121
122
122
## Action customizations
123
123
124
-
Actions could be easily customized.
124
+
Actions can be easily customized.
125
125
126
126
### Action index query
127
127
@@ -143,7 +143,7 @@ This method will be called right before items are retrieved from the database, s
143
143
144
144
### Custom uri key
145
145
146
-
Since your class names could change along the way, you can define a `$uriKey` property to your actions, so the frontend will use always the same `action` query when applying an action:
146
+
Since your class names might change along the way, you can define a `$uriKey` property to your actions, so the frontend will always use the same `action` query when applying an action:
147
147
148
148
```php
149
149
class PublishPostAction extends Action
@@ -169,7 +169,7 @@ public function rules(): array
169
169
```
170
170
171
171
<alerttype="danger">
172
-
Restify doesn't validate the payload automatically as it does for filters, you're free to validate the payload in the handle method.
172
+
Restify doesn't validate the payload automatically as it does for filters, so you're free to validate the payload in the handle method.
173
173
</alert>
174
174
175
175
Always validate the payload as early as possible in the `handle` method:
@@ -190,13 +190,13 @@ By default, any action could be used on [index](#index-actions) as well as on [s
190
190
191
191
## Show actions
192
192
193
-
Show actions are used when you have to apply it for a single item.
193
+
Show actions are used when you have to apply them for a single item.
194
194
195
195
### Show action definition
196
196
197
-
The show action definition is different in the way it receives arguments for the `handle` method.
197
+
The show action definition is different, in a way it receives arguments for the `handle` method.
198
198
199
-
Restify automatically resolves Eloquent models defined in the route id and passes it to the action's handle method:
199
+
Restify automatically resolves Eloquent models defined in the route id and passes them to the action's handle method:
200
200
201
201
```php
202
202
// PublishPostAction.php
@@ -247,13 +247,13 @@ See [get available actions](#get-available-actions) for more details.
247
247
248
248
## Index actions
249
249
250
-
Index actions are used when you have to apply it for a many items.
250
+
Index actions are used when you have to apply them for a many items.
251
251
252
252
### Index action definition
253
253
254
254
The index action definition is different in the way it receives arguments for the `handle` method.
255
255
256
-
Restify automatically resolves Eloquent models sent via the `repositories` key sent into the call payload and passes it to the action's handle method as a collection of items:
256
+
Restify automatically resolves Eloquent models sent via the `repositories` key into the call payload. Then, it passes it to the action's handle method as a collection of items:
The payload should always include a key called `repositories`, which is an array of model keys or the `all` keyword if you want to get all:
292
+
The payload should always include a key called `repositories`, which is an array of model keys or the `all` keyword if you want to get them all:
293
293
294
294
```json
295
295
{
@@ -301,7 +301,7 @@ So Restify will resolve posts with ids in the list of `[1, 2, 3]`.
301
301
302
302
### Apply index action for all
303
303
304
-
You can apply the index action for all models from the database if you send the payload:
304
+
You can apply the index action for all the models from the database if you send the payload:
305
305
306
306
```json
307
307
{
@@ -331,12 +331,12 @@ See [get available actions](#get-available-actions) for more details.
331
331
332
332
## Standalone actions
333
333
334
-
Sometimes you don't need to have an action with models. Let's say for example the authenticated user wants to disable
335
-
his account.
334
+
Sometimes, you don't need to have an action with models. Let's say for example the authenticated user wants to disable
335
+
his/her account.
336
336
337
337
### Standalone action definition:
338
338
339
-
The index action definition is different in the way it doesn't require the second argument for the `handle`.
339
+
The index action definition is different, in a way it doesn't require the second argument for the `handle`.
340
340
341
341
```php
342
342
// DisableProfileAction.php
@@ -401,14 +401,14 @@ sending.
401
401
402
402
## Action Log
403
403
404
-
It is often useful to view a log of the actions that have been run against a model, or seeing when the model was
404
+
Oftentimes, it is quite useful to view a log of the actions that have been run against a model, or see when the model was
405
405
updated, deleted or created (and by whom).
406
406
407
-
Thankfully, Restify makes it a breeze to add an action log to a model by attaching the `Binaryk\LaravelRestify\Models\Concerns\HasActionLogs`trait to the repository's corresponding Eloquent model.
407
+
Thankfully, Restify makes it a breeze to add an action log to a model by attaching the `Binaryk\LaravelRestify\Models\Concerns\HasActionLogs` trait to the repository's corresponding Eloquent model.
408
408
409
409
### Activate logs
410
410
411
-
Simply adding the `HasActionLogs` trait to your model, it will log all actions and CRUD operations into the database into the `action_logs` table:
411
+
By simply adding the `HasActionLogs` trait to your model, it will log all actions and CRUD operations into the database into the `action_logs` table:
412
412
413
413
```php
414
414
// Post.php
@@ -421,7 +421,7 @@ class Post extends Model
421
421
422
422
### Display logs
423
423
424
-
You can display them by attaching to the repository related for example:
424
+
You can display them by attaching them to the related repository for example:
425
425
426
426
```php
427
427
// PostRepository.php
@@ -436,7 +436,7 @@ public static function related(): array
436
436
}
437
437
```
438
438
439
-
So now you can call the posts with logs `api/restify/posts/1?related=logs`, and it will return you the list of actions
439
+
Now you can call the posts with logs `api/restify/posts/1?related=logs`, and it will return you the list of actions
440
440
performed for posts:
441
441
442
442
```json
@@ -460,7 +460,7 @@ performed for posts:
460
460
461
461
### Custom logs repository
462
462
463
-
Definitely you can use your own `ActionLogRepository`. Just ensure you define it into the config:
463
+
You can definitely use your own `ActionLogRepository`. Just make sure you have it defined into the config:
464
464
465
465
```php
466
466
// config/restify.php
@@ -472,7 +472,7 @@ Definitely you can use your own `ActionLogRepository`. Just ensure you define it
472
472
473
473
## Get available actions
474
474
475
-
The frontend which consume your API could check available actions by using exposed endpoint:
475
+
The frontend that consumes your API could check available actions by using this exposed endpoint:
476
476
477
477
```http request
478
478
GET: api/api/restify/posts/actions
@@ -493,9 +493,9 @@ This will answer with a json like:
493
493
494
494
`name` - humanized name of the action
495
495
496
-
`destructive` - you may extend the `Binaryk\LaravelRestify\Actions\DestructiveAction` to indicate to the frontend than
496
+
`destructive` - you may extend the `Binaryk\LaravelRestify\Actions\DestructiveAction` to indicate to the frontend that
497
497
this action is destructive (could be used for deletions)
498
498
499
-
`uriKey` - is the key of the action, will be used to perform the action
499
+
`uriKey` - is the key of the action and it will be used to perform the action
500
500
501
501
`payload` - a key / value object indicating required payload defined in the `rules` Action class
0 commit comments