Skip to content

Commit 0b5b708

Browse files
binarykdaniel-banciuleailichkayaeloquentcoderarthurkirkosa
authored
7.x (#491)
* fix: support ukraine * Clean up & upgrading php + laravel (#464) * fix: cleaning the repository method * Fix styling * fix: wip * fix: wip * fix: wip * fix: wip * fix: wip * fix: wip * feat: drop laravel 8 support * fix: wip * Fix styling * fix: wip * Fix styling * fix: refactoring matches * fix: wip * Fix styling * fix: wip * fix: wip * Larastan (#461) * fix: support ukraine * adding larastan * wip * Fix styling * Fix styling * fix: wip * Fix styling * fix: wip * fix: php 8.1 * fix: cover windows tests Co-authored-by: binaryk <binaryk@users.noreply.github.com> * fix: delete unused Co-authored-by: binaryk <binaryk@users.noreply.github.com> * fix: route method * Fix styling * fix: roadmap * fix: Make sure any action isn't permitted unless the Model Policy exists * fix: wip * Fix styling * fix: Block requests without policy (#466) * fix: Block requests without policy * Fix styling * fix: wip * fix: wip * fix: wip * fix: tests * fix: config Co-authored-by: binaryk <binaryk@users.noreply.github.com> * fix: Adding package tools and fixing related bug (#467) * Tests 2 (#468) * fix: use route helper * Fix styling * fix: tests refactoring * Fix styling * fix: route key * fix: wip * Fix styling * fix: phpunit config * fix: coverage * fix: factories * Fix styling * fix: wip * fix: wip * Fix styling Co-authored-by: binaryk <binaryk@users.noreply.github.com> * fix: wip * fix: wip * fix: wip * Custom logs (#469) * fix: assertables & prototypes * Fix styling * fix: observer for logs * Fix styling * fix: wip * Fix styling * fix: custom logs * fix: wip * Fix styling * fix: sideeffect * Fix styling * fix: wip Co-authored-by: binaryk <binaryk@users.noreply.github.com> * With eager loading (#470) * fix: adding with for the show * fix: cleanup responses using helper * Fix styling Co-authored-by: binaryk <binaryk@users.noreply.github.com> * fix: List restify routes through artisan command (#471) * fix: List restify routes through artisan command * Fix styling * fix: wip * fix: tests Co-authored-by: binaryk <binaryk@users.noreply.github.com> * fix: wip * fix: helpers for action logs * Fix styling * fix: fix eager fields without key in include * fix: wip * fix: custom serializer (#472) * fix: custom serializer * Fix styling * fix: serializer docs Co-authored-by: binaryk <binaryk@users.noreply.github.com> * Fix styling * Relationships nested (#473) * fix: eager loading nested relationships * Fix styling * fix: wip * fix: eager loading nested relationships * fix: wip Co-authored-by: binaryk <binaryk@users.noreply.github.com> * fix: don't check related if no query (#475) * Fix after bulk method calls (#476) * fix after bulk method calls * fix number of calls * revert returns * Fix styling * Keep model attributes for deletedBulk method. (#477) * fix after bulk method calls * fix number of calls * revert returns * keep model attributes * fix: fix psalm and tests (#478) * fix: fix psalm and tests * fix: wip * fix: wip * Performance (#474) * fix: catch issues * Fix styling * fix: ensure eager loading works * Fix styling * fix: performance improvements * Fix styling * fix: related performance improvements * Fix styling * fix: drop cast support * Fix styling * fix: optimize current repository search Co-authored-by: binaryk <binaryk@users.noreply.github.com> * Recursive related (#479) * fix: collection * Fix styling * fix: tests * fix: wip * Fix styling * fix: recursive * Fix styling * fix: recursive related including columns * fix: typo * Fix styling Co-authored-by: binaryk <binaryk@users.noreply.github.com> * Feedback related (#480) * fix: feedback from related pr * Fix styling * fix: wip * fix: wip * Fix styling Co-authored-by: binaryk <binaryk@users.noreply.github.com> * Dynamic meta (#481) * fix: configurable meta render * Fix styling Co-authored-by: binaryk <binaryk@users.noreply.github.com> * fix: formatting (#482) * Docs 7x (#483) * fix: repository generator improvements & sanctum middleware scaffolding * Fix styling Co-authored-by: binaryk <binaryk@users.noreply.github.com> * Docs 7x (#484) * fix: repository generator improvements & sanctum middleware scaffolding * feat: [7.x] Eager fields recognize pattern of the key to retrieve repository. * Fix styling * fix: updating docs for v7 * fix: merge * Fix styling * fix: wip * fix: wip * Fix styling Co-authored-by: binaryk <binaryk@users.noreply.github.com> * Last formatting (#485) * fix: wip * fix: wip * fix: [7.x] Load routes from the application service provider so the d… (#487) * fix: [7.x] Load routes from the application service provider so the developer could disable it. * Fix styling * fix: wip Co-authored-by: binaryk <binaryk@users.noreply.github.com> * fix: [7.x] Loading routes before middleware stack. * fix: wip * Fix styling * fix: Do not resolve current repository from the singleton. * Fix styling * Singleton issues (#492) * fix: [7.x] Singleton issues fixes. * Fix styling * fix: wip * Fix styling * fix: wip * fix: tests Co-authored-by: binaryk <binaryk@users.noreply.github.com> * fix: publish restify before routes * AUTH - Actions (#490) * Update index.md * Update index.md * Update actions.md * Update actions.md * Update fields.md * Update getters.md * Update relations.md * Update repositories-advanced.md * Update repositories.md * Update serializer.md * Update rest-methods.md * Update index.md * Update index.md * Update index.md * Update quickstart.md * Update authentication.md * Update authorization.md * Update profile.md * fix: docs * Fix styling * fix: readme * fix: quickstart docs * Update quickstart.md (#493) Updated the quickstart docs to correct the typo **creates** an abstract `app/Restif/Repository.php` to **creates** an abstract `app/Restify/Repository.php` * Update README.md * [7.x] Nested relationships using the same parent (#494) * fix: [7.x] Singleton issues fixes. * Fix styling * fix: wip * Fix styling * fix: wip * fix: tests * fix: fixing assoc for eager loading * Fix styling * fix: wip parent relationship * Fix styling * fix: wip * Fix styling * fix: fixing recursive issue * Fix styling * fix: upgrading guideline * fix: wip Co-authored-by: binaryk <binaryk@users.noreply.github.com> * fix: wip * [7.x] Cache policies (#496) * fix: [7.x] cache the authorized repository policy * Fix styling * fix: caching policies * Fix styling * fix: docs * fix: docs Co-authored-by: binaryk <binaryk@users.noreply.github.com> * fix: [7.x] Action log observer fix. (#497) * fix: fixing cache enable option (#498) * [7.x] Make testing route method more robust (#500) * Make testing route method more robust * Fix tests * Fix tests * Fix styling * Fix tests * Fix tests * Move action as 3rd param Co-authored-by: arthurkirkosa <arthurkirkosa@users.noreply.github.com> * fix: [7.x] chaning docs category (#499) * [7.x] Fix authorization http code (#501) * fix: [7.x] Use 401 unathorized http code. * fix: wip * fix: adding test * fix: wip * Fix styling * fix: wip * Fix styling Co-authored-by: binaryk <binaryk@users.noreply.github.com> * fix: ensure testing helpers have test coverage (#502) * fix: ensure testing helpers have test coverage * Fix styling Co-authored-by: binaryk <binaryk@users.noreply.github.com> * [7.x] Do not load singleton DTO in tests (#503) * fix: do not load routes twice in tests and don't run singleton for related in tests * Fix styling * fix: wip * Fix styling Co-authored-by: binaryk <binaryk@users.noreply.github.com> * fix: upgrading * feat: making the policy meta method protected (#504) * Fix Gate::check - show - not working (#505) * fix scout when search input is null (#506) Fix when using ElasticSearch: Elastic\Elasticsearch\Exception\ClientResponseException: 400 Bad Request: {"error":{"root_cause":[{"type":"parsing_exception","reason":"[query_string] unknown token [VALUE_NULL] after [query]","line":1,"col":35}],"type":"parsing_exception","reason":"[query_string] unknown token [VALUE_NULL] after [query]","line":1,"col":35},"status":400} * fix: fixing public index method (#513) * Serialize One model (#510) * fix: listing routes in console (#514) * fix: listing routes in console * Fix styling Co-authored-by: binaryk <binaryk@users.noreply.github.com> * Fix styling Co-authored-by: binaryk <binaryk@users.noreply.github.com> Co-authored-by: Daniel Bănciulea <daniel.banciulea@systeady.com> Co-authored-by: ilichkaya <109801809+ilichkaya@users.noreply.github.com> Co-authored-by: Patrick Obafemi <eloquentintech@gmail.com> Co-authored-by: Arthur Kirkosa <arthur.kirkosa@me.com> Co-authored-by: arthurkirkosa <arthurkirkosa@users.noreply.github.com> Co-authored-by: Trương Thanh Tùng <ttungbmt@gmail.com> Co-authored-by: ndifon <malico.yong@gmail.com>
1 parent b425760 commit 0b5b708

File tree

80 files changed

+1534
-661
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+1534
-661
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ You can install the package via composer:
2323
composer require binaryk/laravel-restify
2424
```
2525

26+
## Playground
27+
28+
You can find a playground in the [Restify Demo GitHub repository](https://github.com/BinarCode/restify-demo).
29+
2630
## Videos
2731

2832
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.
8791

8892
### Security
8993

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.com or [message me on twitter](https://twitter.com/LupacescuEuard) instead of using the issue tracker.
9195

9296
## Credits
9397

94-
- [Eduard Lupacescu](https://github.com/binaryk)
98+
- [Eduard Lupacescu](https://twitter.com/LupacescuEuard)
9599
- [Koen Koenster](https://github.com/Koenster)
96100
- [All Contributors](../../contributors)
97101

UPGRADING.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Upgrading
22

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+
39
## From 6.x to 7.x
410

511
High impact:
@@ -13,6 +19,7 @@ High impact:
1319
- `$defaultPerPage` and `$defaultRelatablePerPage` has a type of `int`, if you override this make sure you add `int` type
1420
- `eagerState` method was deleted from the repository, there is no need to call it anymore, the repository will be resolved automatically
1521
- `$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`.
1623
- 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.
1724
- 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:
1825

config/restify.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136

137137
'repositories' => [
138138
/*
139-
| Specify either to serialize index meta (policy) information or not. For performance reasons we recommend to disable it.
139+
| Specify either to serialize index meta (policy) information or not. For performance reasons we recommend disabling it.
140140
*/
141141
'serialize_index_meta' => false,
142142

@@ -145,4 +145,16 @@
145145
*/
146146
'serialize_show_meta' => true,
147147
],
148+
149+
'cache' => [
150+
/*
151+
| Specify the cache configuration for the resources policies.
152+
| When enabled, methods from the policy will be cached for the active user.
153+
*/
154+
'policies' => [
155+
'enabled' => false,
156+
157+
'ttl' => 5 * 60, // seconds
158+
],
159+
],
148160
];

docs-v2/content/en/api/actions.md

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ position: 9
77

88
## Motivation
99

10-
Besides, built in CRUD operations and filtering, Restify allows you to define extra actions for your repositories.
10+
Built in CRUD operations and filtering, Restify allows you to define extra actions for your repositories.
1111

12-
Let's say you have a list of posts, and you have to publish them. Usually for this kind of operations, you have to define a custom route like:
12+
Let's say you have a list of posts and you have to publish them. Usually, for these kind of operations, you have to define a custom route like:
1313

1414
```php
1515
$router->post('posts/publish', PublishPostsController::class);
@@ -18,19 +18,19 @@ $router->post('posts/publish', PublishPostsController::class);
1818

1919
public function __invoke(RestifyRequest $request)
2020
{
21-
...
21+
//...
2222
}
2323
```
2424

25-
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.
2626

27-
So, code readability, testability and maintainability become hard.
27+
On that wise, code readability, testability and maintainability may become hard.
2828

2929
## Action definition
3030

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.
3232

33-
It could be generated by using the command:
33+
It could be generated by using the following command:
3434

3535
```bash
3636
php artisan restify:action PublishPostsAction
@@ -98,7 +98,7 @@ POST: api/restify/posts/actions?action=publish-posts-action
9898
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)
9999

100100

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:
102102

103103
```json
104104
{
@@ -108,7 +108,7 @@ The payload could be any type of json data, however, if you're using an [index-a
108108

109109
### Handle action
110110

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`:
112112

113113
```php
114114
public function handle(ActionRequest $request, Collection $models)
@@ -121,7 +121,7 @@ public function handle(ActionRequest $request, Collection $models)
121121

122122
## Action customizations
123123

124-
Actions could be easily customized.
124+
Actions can be easily customized.
125125

126126
### Action index query
127127

@@ -143,7 +143,7 @@ This method will be called right before items are retrieved from the database, s
143143

144144
### Custom uri key
145145

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:
147147

148148
```php
149149
class PublishPostAction extends Action
@@ -169,7 +169,7 @@ public function rules(): array
169169
```
170170

171171
<alert type="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.
173173
</alert>
174174

175175
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
190190

191191
## Show actions
192192

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.
194194

195195
### Show action definition
196196

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.
198198

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:
200200

201201
```php
202202
// PublishPostAction.php
@@ -247,13 +247,13 @@ See [get available actions](#get-available-actions) for more details.
247247

248248
## Index actions
249249

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.
251251

252252
### Index action definition
253253

254254
The index action definition is different in the way it receives arguments for the `handle` method.
255255

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:
257257

258258
```php
259259
// PublishPostAction.php
@@ -289,7 +289,7 @@ The post URL:
289289
POST: api/restfiy/posts/actions?action=publish-posts-action
290290
```
291291

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 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:
293293

294294
```json
295295
{
@@ -301,7 +301,7 @@ So Restify will resolve posts with ids in the list of `[1, 2, 3]`.
301301

302302
### Apply index action for all
303303

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:
305305

306306
```json
307307
{
@@ -331,12 +331,12 @@ See [get available actions](#get-available-actions) for more details.
331331

332332
## Standalone actions
333333

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.
336336

337337
### Standalone action definition:
338338

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`.
340340

341341
```php
342342
// DisableProfileAction.php
@@ -401,14 +401,14 @@ sending.
401401

402402
## Action Log
403403

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
405405
updated, deleted or created (and by whom).
406406

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.
408408

409409
### Activate logs
410410

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:
412412

413413
```php
414414
// Post.php
@@ -421,7 +421,7 @@ class Post extends Model
421421

422422
### Display logs
423423

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:
425425

426426
```php
427427
// PostRepository.php
@@ -436,7 +436,7 @@ public static function related(): array
436436
}
437437
```
438438

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
440440
performed for posts:
441441

442442
```json
@@ -460,7 +460,7 @@ performed for posts:
460460

461461
### Custom logs repository
462462

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:
464464

465465
```php
466466
// config/restify.php
@@ -472,7 +472,7 @@ Definitely you can use your own `ActionLogRepository`. Just ensure you define it
472472

473473
## Get available actions
474474

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:
476476

477477
```http request
478478
GET: api/api/restify/posts/actions
@@ -493,9 +493,9 @@ This will answer with a json like:
493493

494494
`name` - humanized name of the action
495495

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
497497
this action is destructive (could be used for deletions)
498498

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
500500

501501
`payload` - a key / value object indicating required payload defined in the `rules` Action class

0 commit comments

Comments
 (0)