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: docs/docs/3.0/repository-pattern/repository-pattern.md
+90-1Lines changed: 90 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,6 +43,8 @@ You have available the follow endpoints:
43
43
| GET |`/restify-api/posts`| index |
44
44
| GET |`/restify-api/posts/{post}`| show |
45
45
| POST |`/restify-api/posts`| store |
46
+
| POST |`/restify-api/posts/bulk`| store multiple |
47
+
| POST |`/restify-api/posts/bulk/update`| store multiple |
46
48
| PATCH |`/restify-api/posts/{post}`| update |
47
49
| PUT |`/restify-api/posts/{post}`| update |
48
50
| POST |`/restify-api/posts/{post}`| update |
@@ -133,7 +135,7 @@ public static function collectMiddlewares(RestifyRequest $request): ?Collection
133
135
134
136
## Dependency injection
135
137
136
-
The Laravel [service container](https://laravel.com/docs/6.x/container) is used to resolve all Laravel Restify repositories.
138
+
The Laravel [service container](https://laravel.com/docs/7.x/container) is used to resolve all Laravel Restify repositories.
137
139
As a result, you are able to type-hint any dependencies your `Repository` may need in its constructor.
138
140
The declared dependencies will automatically be resolved and injected into the repository instance:
139
141
@@ -208,6 +210,15 @@ entire logic of a specific action. Let's say your `save` method has to do someth
208
210
}
209
211
```
210
212
213
+
### store bulk
214
+
215
+
```php
216
+
public function storeBulk(Binaryk\LaravelRestify\Http\Requests\RepositoryStoreBulkRequest $request)
217
+
{
218
+
// Silence is golden
219
+
}
220
+
```
221
+
211
222
### update
212
223
213
224
```php
@@ -217,6 +228,17 @@ entire logic of a specific action. Let's say your `save` method has to do someth
217
228
}
218
229
```
219
230
231
+
### update bulk
232
+
233
+
// $row is the payload row to be updated
234
+
235
+
```php
236
+
public function updateBulk(RestifyRequest $request, $repositoryId, int $row)
237
+
{
238
+
// Silence is golden
239
+
}
240
+
```
241
+
220
242
### destroy
221
243
222
244
```php
@@ -592,4 +614,71 @@ you may want to force eager load a relationship in terms of using it in fields,
592
614
public static $with = ['posts'];
593
615
```
594
616
617
+
## Store bulk flow
618
+
619
+
However, the `store` method is a common one, the `store bulk` requires a bit of attention.
620
+
621
+
### Bulk field validations
622
+
623
+
Similar with `store` and `update` methods, `bulk` rules has their own field rule definition:
624
+
625
+
```php
626
+
->storeBulkRules('required', function () {}, Rule::in('posts:id'))
627
+
```
628
+
629
+
The validation rules will be merged with the rules provided into the `rules()` method. The validation will be performed
630
+
by using native Laravel validator, so you will have exactly the same experience. The validation `messages` could still be used as usual.
631
+
632
+
### Bulk Payload
633
+
634
+
The payload for a bulk store should contain an array of objects:
635
+
636
+
```json
637
+
[
638
+
{
639
+
"title": "First post"
640
+
},
641
+
{
642
+
"title": "Second post"
643
+
}
644
+
]
645
+
```
646
+
647
+
### Bulk after store
648
+
649
+
After storing an entity, the repository will call the static `bulkStored` method from the repository, so you can override:
650
+
651
+
```php
652
+
public static function storedBulk(Collection $repositories, $request)
653
+
{
654
+
//
655
+
}
656
+
```
657
+
658
+
## Update bulk flow
659
+
660
+
As the store bulk, the update bulk uses DB transaction to perform the action. So you can make sure that even all entries, even no one where updated.
661
+
662
+
### Bulk update field validations
663
+
664
+
```php
665
+
->updateBulkRules('required', function () {}, Rule::in('posts:id'))
666
+
```
667
+
668
+
### Bulk Payload
669
+
670
+
The payload for a bulk update should contain an array of objects. Each object SHOULD contain an `id` key, based on this, the Laravel Restify will find the entity:
0 commit comments